There is one div which changes frequently it’s innerHTML by ajax. Once the page loads, jQuery function() works but when innerHTML changes by ajax then some functionality doesn’t work. I checked the code using firebug and try to explain it in short.**
I think DOM loads the js file only when the page loaded first time and if ajax modifies innerHTML then function is not invoked somehow.What you say? what could be solution according to you?
HTML page
<body>
<div class="_div_change"> dynamically class add by jQuery function()
here contenet is added by ajax functionality
</div>
<script type="text/javascript">
$(function(){
$('._div_change').addClass('.div_class');
});
</script>
</body>
Loading first time & class is added by fn() |only div innerHTML modified by ajax ***
|
<div class="_div_change div_class"> | <div class="_div_change">
innerHTML elements added successfully| innerHTML elements altered successfully
</div> | </div>
Your script is incomplete, but assuming that it looks like this:
…then what you’re doing there is telling jQuery to run that function once when the DOM is initially loaded (calling
$()with a function is a shortcut tojQuery.ready). If you want to re-run that function when you update thediv‘s contents via ajax, you’ll have to do that in yoursuccesshandler on the ajax call.You can give jQuery a function that it will call whenever any ajax call is complete, via
jQuery.ajaxSuccess, which may be useful.