When I bind a function to a checkbox element like:
$("#myCheckbox").click( function() {
alert($(this).is(":checked"));
});
The checkbox changes its checked attribute before the event is triggered, this is the normal behavior, and gives an inverse result.
However, when I do:
$("#myCheckbox").click();
The checkbox changes it checked attribute after the event is triggered.
My question is, is there a way to trigger the click event from jQuery like a normal click would do (first scenario)?
PS: I've already tried with trigger('click')
;
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…