Morning people. How to make my javascript or jquery works in dynamically generated content.
Basically, i have created web page that generates contents, base on wha
Taking a wild stab in the dark here since your question isn't very well-described, but perhaps you're trying to use .click()
and so on to bind events to things that are getting dynamically loaded into the page?
If so, you probably want to look at .on() instead.
For dynamically generated fields use .on() JQuery method:
$(document).on('click', '#MyID', function(e) {
e.preventDefault(); // or you can use "return false;"
});
You need to use live event.
As an example, if your generated content contain a click event, you could do this:
$(".something").live("click", function({
// do something
)};
For dynamically generated elements you should delegate the events, you can use the on
method:
$(function() {
$(document).on('click', '#submitUser', function(e) {
var fname = $("#fname").val();
$("#theresult").text(fname);
e.preventDefault();
});
});
live()
method is deprecated.