开发者

JQuery processing interactive content

开发者 https://www.devze.com 2023-03-19 20:15 出处:网络
I noticed that in jquery appended text won\'t be processed by jquery functions. For example, you append a code containing dropdown-list and you have a function that invokes on changing its value. This

I noticed that in jquery appended text won't be processed by jquery functions. For example, you append a code containing dropdown-list and you have a function that invokes on changing its value. This function works on existing code only, not on appended one.


And the correct answer is:

Instead of using:

$('#purchase-table select').change(function() {
});

Use:

$('#purchase-table select').live('change', function() {
}); 

You need it to be able to process ajax-appended content by your jquery functions. Have a nice day.

开发者_JAVA百科Thanks to everyone helped.


You can use JQuery .live()

Append new content:

$('body').append('<div class="clickme">Another target</div>');

Add handler to it:

$('.clickme').live('click', function() {
  // Live handler called.
});

Then clicks on the new element will also trigger the handler.


The easiest way to handle events on interactive content is the jQuery.live method.

http://api.jquery.com/live/

Description: Attach a handler to the event for all elements which match the current selector, now and in the future.

0

精彩评论

暂无评论...
验证码 换一张
取 消