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:
    1. move code external file , reference file after jquery inclusion
    2. move jquery declaration head-section (not recommended slow down page load)

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -