Skip to content Skip to sidebar Skip to footer

How To Run Click Function After Default Behaviour Of A Element

My code )){ alert("Checked"); } else { alert("Not Checked"); } }); });​

Demo

Solution 2:

Try this instead:

$("body").on("click", ".mes_sel", function() {
    if ($(this).is(":checked")) {
        alert("Checked");
    }
    elsealert("Not Checked");
});​

jsFiddle example.

Solution 3:

I ran into this problem a while back - I also found that different browsers handled this differently. Chrome was the worst offender, if I remember correctly.

This isn't necessarily the best solution, but you could attach a custom attribute to each checkbox, say "isChecked", and then base your function off this attribute like so:

if ($("mes_sel").attr("isChecked") == "true") { ... }

Like I said, not the best solution as you will have to manually flip the "isChecked" attribute in order to stay consistent with the actual checked value of the checkbox, but it will work if nothing more elegant will work for you.

If you'd like an example of this , check out this jsFiddle:

http://jsfiddle.net/NathanFriend/GAP2j/

This turns regular radio buttons into "toggleable" radio buttons - I was forced to use this custom attribute method because of the different way browsers execute onclick events.

Post a Comment for "How To Run Click Function After Default Behaviour Of A Element"