javascript - jQuery .change() not firing - Stack Overflow

Just working on some small pages to be elements of a much larger project and am pletely confused at my

Just working on some small pages to be elements of a much larger project and am pletely confused at my current problem here is my code:

<script src=".5.1/jquery.min.js"></script>
<STYLE TYPE="text/css">
  .questionBlock { font-size: x-large; color: red }
</STYLE>

<script type="text/javascript">
$(document).ready(function() { 
alert("sdsd")
$("input[@name='questionType']").change(function(){
    alert("dfdfdf");
    var selected = $("form input:radio:checked").val();
    alert(selected);
})
});

</script>

<form action="">
<input type="radio" name="questionType" value="closed" /> Closed Endeded<br />
<input type="radio" name="questionType" value="matrix" /> Matrix Question<br />
<input type="radio" name="questionType" value="open" /> Open Ended
</form>

<div class="questionBlock" id="closed">lol</div>
<div class="questionBlock" id="open">rol</div>
<div class="questionBlock" id="matrix">bol</div>

But the change event never fires, regardless of browser, I've tried using bind as well but it's driving me up the wall!

Just working on some small pages to be elements of a much larger project and am pletely confused at my current problem here is my code:

<script src="https://ajax.googleapis./ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<STYLE TYPE="text/css">
  .questionBlock { font-size: x-large; color: red }
</STYLE>

<script type="text/javascript">
$(document).ready(function() { 
alert("sdsd")
$("input[@name='questionType']").change(function(){
    alert("dfdfdf");
    var selected = $("form input:radio:checked").val();
    alert(selected);
})
});

</script>

<form action="">
<input type="radio" name="questionType" value="closed" /> Closed Endeded<br />
<input type="radio" name="questionType" value="matrix" /> Matrix Question<br />
<input type="radio" name="questionType" value="open" /> Open Ended
</form>

<div class="questionBlock" id="closed">lol</div>
<div class="questionBlock" id="open">rol</div>
<div class="questionBlock" id="matrix">bol</div>

But the change event never fires, regardless of browser, I've tried using bind as well but it's driving me up the wall!

Share Improve this question asked Mar 4, 2011 at 12:01 user644666user644666 331 silver badge4 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 5

jQuery attribute selectors don't need @ prefix (like XPath). Change your code like this:

$("input[name='questionType']").change(function(){

Here is a working version.

you need to remove the @ fiddle

$(document).ready(function() { 

    $('input[name="questionType"]').change(function(){
        alert("dfdfdf");
        var selected = $("form input:radio:checked").val();
        alert(selected);
    })
    });

jQuery does not use "@" in Xpath-style attr selectors anymore. This being the case, your selector does not match anything.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745283732a4620433.html

相关推荐

  • javascript - jQuery .change() not firing - Stack Overflow

    Just working on some small pages to be elements of a much larger project and am pletely confused at my

    12小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信