Jquery Triggered Newly Added Html Code
Example I had 2 html input
Solution 1:
I think the problem is not with click on new input but with autocomplete on new input. When you add new element with
$('.wrap').append('<input class="autocomplete" name="auto_3" />')
You must attach autocomplete to this new field, so
$('input[name="auto_3"]').autocomplete();
Or make autocomplete with livequery plugin: https://stackoverflow.com/a/4551313/657584
Solution 2:
Use .on()
: http://api.jquery.com/on
$('.wrap').on('click', '.autocomplete', function(){
// your code here// $(this).autocomplete(); // or whatever.
});
Using the .on()
method you delegate your click handler to existant and future elements that will be added to the DOM, something like the (newly) deprecated (from jQ 1.7) .live()
From the DOCS:
$("a.offsite").live("click", function(){ alert("Goodbye!"); }); // jQuery 1.3+
$(document).delegate("a.offsite", "click", function(){ alert("Goodbye!"); }); // jQuery 1.4.3+
$(document).on("click", "a.offsite", function(){ alert("Goodbye!"); }); // jQuery 1.7+
Post a Comment for "Jquery Triggered Newly Added Html Code"