. I would like to prevent the element's default behavior (...">

How to partially preventDefault ()?

Inside there is <label>an element <a href="#">. I would like to prevent the element's default behavior <a>(i.e. Navigation), but it should perform the element's default behavior <label>(i.e. Set a checkbox inside it).

Test case: http://jsfiddle.net/3M6WE/ . By clicking foo, check the box. Pressing bardoes not move, but does not toggle the checkbox.

How can I <a>not move the item but toggle this checkbox? I would like to avoid hacks, for example, toggle the checkbox manually. I am looking for "partially" preventDefaultif it is available.

+5
source share
3 answers

():

http://jsfiddle.net/3M6WE/11/

$("a").on("click", function(e) {
    e.stopPropagation();
    $(this).parent().click();
    // do stuff...
    e.preventDefault();
});

, , preventDefault();

+3

, :

MDN:

Gecko 8.0 (Firefox 8.0/Thunderbird 8.0/SeaMonkey 2.5) <label>, <label> s. click - <label>, WebKit Internet Explorer click <label>. Gecko 8.0 ( <label> s) Firefox (. 646157).

+2
+2

All Articles