I have a @Html.DropDownList which calls a jquery function. But it failed to call the function. I have tried-
$(document).ready(function () {
$('.test').change(function () {
alert("1");
});
});
@Html.DropDownList("PropertyContent", ViewBag.PropertyList as List<SelectListItem>, new { @class="test"})
and
function test() {
alert("1");
}
@Html.DropDownList("PropertyContent", ViewBag.PropertyList as List<SelectListItem>, new { onchange="test();"})
@Scripts.Render("~/bundles/jqueryval") is also included in the view
Whats wrong here?
Your jQuery selector is wrong, use the id-selector instead:
$(document).ready(function () {
$('#PropertyContent').change(function () {
alert("1");
});
});
A few more possible errors:
$
is not known. Possible solutions:
$(document).ready(function () {
$('.test').change(function () {
alert("1");
});
});
$('.test').change(function () {
// on this part u need to add '.'
in test
u forgot that it is a class.
You can also use following code.
$(document).ready(function () {
$(".test").live("change",function () {
alert("1");
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With