javascript - MVC4 view is not detecting JQuery -
i have @html.dropdownlist calls jquery function. failed call function. have tried-
$(document).ready(function () { $('.test').change(function () { alert("1"); }); }); @html.dropdownlist("propertycontent", viewbag.propertylist list<selectlistitem>, new { @class="test"})
and
function test() { alert("1"); } @html.dropdownlist("propertycontent", viewbag.propertylist list<selectlistitem>, new { onchange="test();"}) @scripts.render("~/bundles/jqueryval") included in view
whats wrong here?
your jquery selector wrong, use id-selector instead:
$(document).ready(function () { $('#propertycontent').change(function () { alert("1"); }); });
a few more possible errors:
- jquery not referenced in page. check this, open firebug, chrome dev tools or ie dev tools , check whether have errors
- a common error include $(document).ready inside view, , reference jquery @ bottom. generate error because @ point
$
not known. possible solutions:- move code external file , reference file after jquery inclusion
- move jquery declaration head-section (not recommended slow down page load)
Comments
Post a Comment