Jquery in javascript function requires two clicks

I wrote Simpe inline edit using jquery. The plugin works very well, but I have a problem when I call the script in the javascript function, it takes 2 clicks to activate the plugin. Does anyone know a way to solve this problem. I want it with one click! Thank you in advance.

<a onclick="update(1)"> Let update<a/> function update(id) { $("#edit" + id).kb_edit(); } 
0
source share
2 answers

If the function in the plugin requires a click event handler that you configure internally, then it will not be configured until you run .kb_edit() .

So, the first click launches .kb_edit() , which sets the click handler.

Then the second click actually launches everything that was configured with the first click.

+1
source

Good for starters, you can clean it up a bit without using onclick ...

 <a id="myAnchor">Let update</a> $(document).ready(function() { $("#myAnchor").click(function(){ ///put your update code here including the kb_edit code }); }); 

or if you have a series of this, you can use <a class="myAnchor">...</a> and change the jquery selector:

  $(".myAnchor").click(function(){ 
0
source

All Articles