Sunday, May 12, 2024
 Popular · Latest · Hot · Upcoming
139
rated 0 times [  140] [ 1]  / answers: 1 / hits: 26843  / 13 Years ago, mon, september 12, 2011, 12:00:00

This is my code:



<html>
<head>
<script src=https://ajax.googleapis.com/ajax/libs/jquery/1.6.3/jquery.min.js></script>
<script>
$(document).ready(function() {
$('.chk').live('change', function() {
alert('change event fired');
});
$('a').click(function() {
$('.chk').attr('checked', true);
});
});
</script>
</head>
<body>
<div class=chkHolder>
<input type=checkbox class=chk name=a id=a />
<input type=checkbox class=chk name=b id=b />
</div>
<a href=#>check all</a>
</body>
</html>


When I click on the check all hyperlink, I want the change event fired for each of the checkboxes. However, that is not happening.



Any ideas?



Many thanks!


More From » jquery

 Answers
52

use: $('.chk').attr('checked', true).change();



Live example: http://jsfiddle.net/NRPSA/1/


[#90148] Friday, September 9, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kieraelsies

Total Points: 718
Total Questions: 103
Total Answers: 104

Location: England
Member since Sun, May 21, 2023
1 Year ago
;