Search buttons sometimes require a second click for unknown reason
Search buttons sometimes require a second click for unknown reason
Hi everyone,
This is my first request here. I hope, everything is as required.
My knowledge is super superficial, but with what I've learned from the documentation and particularly this forum post and Daimian's reply, I've been able to realize "clickable hashtags" - in other words, buttons within a table that trigger a search for keywords.
I'm quite pleased with it. However, sometimes, a hashtag button needs to be clicked twice. More precisely, it seems as if, sometimes, a first click somewhere in the table is required to set the focus before a hashtag button is working.
Unfortunately, I cannot tell the steps on how to reproduce this. But directly after loading the table, the first click on a hashtag never works.
Here is the test case: http://live.datatables.net/humikesi/1/edit
Is there a way to optimize the search function so that the hashtag buttons always work?
Replies
You have code to create a click event handler within another event handler. The first click will initialize the
$(".hashtagSearch").click(function()
click handler. The second click will work. The problem with is each time you click it will create an additional.hashtagSearch
handler resulting in the function running multiple times.You need to create a jQuery delegated event as shown in this exaample. I updated your example to show this. I commented out the lines you need to remove and added
.hashtagsearch
to the initial event handler.http://live.datatables.net/humikesi/3/edit
Kevin
Thank you so much, Kevin, for your amazingly quick, detailed and kind answer!
I already knew the example you've posted, since it is the one that explains why events only work on the first page. FAQ answer number 2. But my limited comprehension didn't allow me to understand that it also included the solution to this issue.
Thanks!
Georg