Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

load innerHtml of ajax loaded div

I have a div which get's its content loaded through ajax .load("ajaxcontent.php").

Inside this div, we produce many other divs. I want to get the content of one of these divs.

I've tried var insidecontent=$('#topdiv').html(); but it returns null.

is there a trick to getting such values?

index.html

<div id="news"></div>

ajaxcontent.php

<div id="topdiv">Hello World</div>
<div id="middiv">This is the mid div</div>
<div id="botdiv">This is the bottom</div>

javascript:

$("#news").load("ajaxcontent.php");

$(document).delegate("#total", "keyup", function (e) {
        if(e.which!=13){
            var insidecontent=$('#topdiv').html();
        }
    });
like image 308
Daku Daku Avatar asked Dec 04 '25 11:12

Daku Daku


1 Answers

Are you accessing the content after the load function completes its execution ?

$("#firstDiv").load("serverpage.aspx",function(){

      // Now access the content
       var insideContent=$("#topDiv").html();

});

EDIT : After the op posted his code

wrap the delegate binding inside document.ready like this

$(function(){
  $(document).delegate("#total", "keyup", function (e) {
        if(e.which!=13){
            var insidecontent=$('#topdiv').html();
        }
    });
});
like image 123
Shyju Avatar answered Dec 06 '25 23:12

Shyju



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!