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

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -