jquery - How to avoid loosing focus on click of anchor tag? -


i have input type text element , anchor element, don't want loose focus on click of anchor tag if focus on input text element. have tried following not work.

html:

<input type = 'text' value='click here first' /> <a href='javascript:void(null);' id='nothing'>do nothing</a> 

jquery code:

$('#nothing').bind('click', function(e){     e.preventdefault(); }) 

above not work me. can tell me missing here?

i have faced similar problem try using 'mousedown' instead of click event.

here demo

<input type = 'text' value='click here first' /> <a href='javascript:void(null);' id='nothing'>clicking not loose focus input field!</a>  $('#nothing').bind('mousedown', function(e){     e.preventdefault(); }) 

Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -