html - How to disable jQuery click event on label? -
here example fiddle
html:
<div class="wrapper"> <label class="control-label" for="topicwords">label</label> <div class="controls"> <input type="text" id="topicwords"> </div> </div> <br/><br/> <span id="message"></span>
js:
$('.wrapper').on('click','input#topicwords', function() { $('#message').fadein('fast').text('clicked').fadeout('slow'); })
click event runs on both input#topicwords
or label
. how make run when input#topicwords
clicked
is there other way except than:
$(".control-label[for='topicwords']").on('click', function() { return false; });
or shortcut:
$(".control-label[for='topicwords']").on('click', false);
update: wrapper's content dynamic, don't have div class controls.
if understand problem correctly, solution you've added way go. reason why click event fires when click on label because of attribute on label.
it says if click me label put focus on input specified in attribute.
besides solution gave. can optionally remove attribute of label want?
Comments
Post a Comment