james hofer
james hofer

Reputation: 53

Can't get div inner HTML on jQuery ready function

I have some code on my page like:

$(document).ready(function(){

//code

});

And on jQuery ready, there is a code to get a div inner HTML:

var tmp = document.getElementById("content").InnerHTML;

It returns undefined. As I know jQuery ready runs when page HTML is completely loaded. But it can't just find div!

jQuery including and div id are correct.

Any ideas?

Upvotes: 0

Views: 1497

Answers (2)

benjarwar
benjarwar

Reputation: 1804

If you're using jQuery already, why not use it to find your DOM element? Assuming your div has an ID of "content":

$(document).ready(function(){
  var $tmp = $("#content"),
      html = $tmp.html();
});

Upvotes: 2

Oliver
Oliver

Reputation: 1644

var tmp = document.getElementById("content").InnerHTML;

This would work, except InnerHTML is not a property of HTMLElement. You simply misspelt innerHTML.

Try

                                             v

var tmp = document.getElementById("content").innerHTML;

                                             ^

Upvotes: 6

Related Questions