Solve jQuery Ajax dynamic new new nodes can’t trigger a problem with clicking event

When writing AJAX loading data, it was found that the Demo node element added later, lost the previous click event. Why is we going to solve the incident?

In fact, the simplest method is to write onclick = “” directly in the label, but this is actually a little low, the best way is to give Class name Bind a Click event.

Solving the two solutions for jQuery Ajax dynamic new nodes that cannot trigger event problems, in order to achieve a better demo effect, assume that there is code of the following structure under a page of Body:

  A1 
  • A2
  • A3
  • $ ("# demo"). Click ( Function () {$ ("# demo"). Append ('
AAA4 ); // Dynamic image of the end of UL add a new element});
  • Method 1: Use the Live:

    function to bind one or more event handler to the selected element, and specify that these A function running when an event occurs. The current and future elements that match the selector via the Live () function. For example, elements created by script dynamically.

    $ (‘. Demo1’). Live (‘click’, function () {alert (‘ok’);}
      Method 2: Use ON:  
    can be bound to its father can be bound by ON method. Among the stages or BODY, the implementation is as follows:

    $ (“# deMo “). ON (‘Click’, ‘. Demol’, Function () {Alert (‘OK’)});

    By two methods above, You can solve the problem of jQuery Ajax dynamic new nodes that cannot trigger a click event. I know the method, try it.
      The above is the Solution to you to the solution to you. JQuery Ajax dynamic new node cannot Trigger a problem with the incident, I hope to help everyone. If you have any questions, please leave a message, the small package will reply to everyone in time. I am very grateful to everyone in Tumi Cloud website!  
    © Copyright Notice
    THE END
    Just support it if you like
    like0
    share
    comment Grab the couch

    Please log in to comment