admin管理员组文章数量:1310891
I am trying, using jquery, to trigger an event when a child element, in this case select, changes.
Here is my HTML:
<div id="addForm" ng-repeat="forme in formes" class="row addForm">
<div class="col-lg-2 col-md-2 col-sm-3 col-xs-6">
<select id="geo_{{forme.id}}" ng-model="forme.geo" class="form-control">
<option value="rectangle">Rectangle</option>
<option value="triangle">Triangle rectangle</option>
<option value="cercle">cercle</option>
</select>
</div>
</div>
The javaScript that is not working yet:
$(document).ready(function () {
$(document.body).on("change", "#addForm > select", function () {
alert(this.value);
});
});
OR
$(document).ready(function () {
$(document.body).on("change", ".addForm > select", function () {
alert(this.value);
});
});
Both method are not working
What is wrong with this?
I am trying, using jquery, to trigger an event when a child element, in this case select, changes.
Here is my HTML:
<div id="addForm" ng-repeat="forme in formes" class="row addForm">
<div class="col-lg-2 col-md-2 col-sm-3 col-xs-6">
<select id="geo_{{forme.id}}" ng-model="forme.geo" class="form-control">
<option value="rectangle">Rectangle</option>
<option value="triangle">Triangle rectangle</option>
<option value="cercle">cercle</option>
</select>
</div>
</div>
The javaScript that is not working yet:
$(document).ready(function () {
$(document.body).on("change", "#addForm > select", function () {
alert(this.value);
});
});
OR
$(document).ready(function () {
$(document.body).on("change", ".addForm > select", function () {
alert(this.value);
});
});
Both method are not working
What is wrong with this?
Share Improve this question edited Mar 13, 2016 at 5:21 Ibrahim Khan 20.8k7 gold badges45 silver badges56 bronze badges asked Mar 13, 2016 at 5:11 MadeInDreamsMadeInDreams 2,1465 gold badges34 silver badges67 bronze badges1 Answer
Reset to default 7This is not working because, addForm
is a class
not an id
.
$(document).on("change", ".addForm select", function () {
alert(this.value);
});
use .classSelector
instead of an #id
selector.
Also I missed out pointing another one error. That is, select
is not a direct child of .addForm
it is a descendant. Use descendant selector
instead of a child selecor
.
DEMO
本文标签: javascriptJquery child element on changeStack Overflow
版权声明:本文标题:javascript - Jquery child element on change - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741865579a2401881.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论