Lost click () event after ajax call?

On the next web page liamharding.com/pgi.php I have a options panel on the left side of the page that opens and closes after clicking on the arrow of the panels, this works fine until you select a market (for testing, use one of the markets "Random Walk "and click" Show / Refesh Graphs "), then it makes an ajax call using the get_graph(forexName, myCount, divIsNew) function get_graph(forexName, myCount, divIsNew) .

As soon as this call is completed, the graph (s) is displayed, and then my event with click () parameters does not work?

Ajax call returns data in ajax_data variable, the problem occurs when I execute the following code var jq_ajax_data = $("<div/>").html(ajax_data); . I need to wrap it so that I can extract data from it using jQuery. If this line of code is commented out, the click () event works fine.

Hope someone can help, I spent a lot of time, but can not find what the problem is.

+4
source share
3 answers

You should not use .live as above, it is deprecated. Instead, you should use .on for example.

 $(document).on('click', '.selector', function(){ //Your code here }); 
+19
source

It's hard to say what exactly causes the click event to get lost without seeing the full code, but you can try setting the click as a live event as follows:

 $("#clickableItem").live("click", function() { //do stuff }); 
+6
source

You are replacing the contents of div with new html. the new html will not have click events assigned to it.

Use the command . live to always have the elements they refer to.

+5
source

Source: https://habr.com/ru/post/1312045/


All Articles