1

I have a webpage and it have html content with id.i am calling a function on onclick. Everything seems working if i am making changes into static content but when i am trying to call any jQuery function like html,append etc... with my dynamic content then it is not working .

As far as i understand it's because of Dom not getting updated with new content.So i would like to know how can i update dom after loading dynamic data.

A demo code below ..

jQuery( document ).ready(function($) {
    var width=$( window ).width();
    if(width <= 768){           
        $('#extraslidercontent').html("<div class='container html_mb' style='background-color:#f29a1f;width:100%;max-width: 100%;'><div class='template-page content  av-content-full alpha units'><div class='post-entry post-entry-type-page post-entry-3291'><div class='entry-content-wrapper clearfix'>\
            "+$('#testtt2').html()+"</div></div></div></div><div class='container css_mb' style='width:100%;max-width: 100%;'><div class='template-page content  av-content-full alpha units'><div class='post-entry post-entry-type-page post-entry-3291'><div class='entry-content-wrapper clearfix'>\
            "+$('#testtt3').html()+"</div></div></div></div><div class='container wp_mb' style='background-color:#493c59;width:100%;max-width: 100%;'><div class='template-page content  av-content-full alpha units'><div class='post-entry post-entry-type-page post-entry-3291'><div class='entry-content-wrapper clearfix'>\
            "+$('#testtt1').html()+"</div></div></div></div>");
        updte();
}

after loading data in to testtt2 id i am trying to use an id which is in it's content.

Let me know if i missed anything to explain.

baao
  • 71,625
  • 17
  • 143
  • 203

1 Answers1

2

You will need to use event delegation for the new element.

$('body').on('click', '#some-id', function () {});

Or for older jQuery ( < 1.7)

$('body').delegate('#some-id', 'click', function () {});
Cjmarkham
  • 9,484
  • 5
  • 48
  • 81