$(this) contains a jQuery wrapper (with lots of functions) whereas this is solely the DOM object.
+6
A:
Otávio Décio
2009-06-30 21:18:59
That I understand, however...what exactly is the difference between the functions? And does jQuery change the functionality of other DOM events when triggered through a jQuery-wrapped element?
Thomas
2009-06-30 21:21:10
+2
A:
The fact that counter is going up gave me the clue that there is a link between checked attribute, which you are using, and firing the click event manually.
I searched Google for 'jquery checkbox click event raise' and found this link, where author faces the exact same problem and the workaround he used.
On a side note, I think you can simplify your code further:
$j('input[type=checkbox].vote_item').click(
function()
{
var maxNumberOfChoices = 5;
//get number of checked checkboxes.
var currentCheckedCount = $j('input[type=checkbox].vote_item :checked');
if(currentCheckedCount > maxNumberOfChoices)
{
//It's useful if you show how many choices user can make. :)
alert('You can only select maximum ' + maxNumberOfChoices + ' checkboxes.');
return false;
}
return true;
});
SolutionYogi
2009-06-30 21:38:53