Reputation: 1793
my code is here which is not returning the result i want
var content = "<div id='content_dv'>";
content += "<table border='1' style='height:auto;width:auto;'>";
content += "<tr>";
content += "<td>";
content += "This is row 1";
content += "</td>";
content += "</tr>";
content += "<tr>";
content += "<td>";
content += "This is row 2";
content += "</td>";
content += "</tr>";
content += "<tr>";
content += "<td>";
content += "This is row 3";
content += "</td>";
content += "</tr>";
content += "</table>";
content += "</div>";
alert($(content).find('#content_dv').html());
alert("height "+$(content).find('#content_dv').height());
alert("width " + $(content).find('#content_dv').width());
my content variable has some html and i want to show the data with in div id called "content_dv" and also i need to determine the height & width of the div and height & width of inner html of div.
so please help me why my code is not working. what wrong in my code. thanks
Upvotes: 2
Views: 196
Reputation: 86
The important thing is here the content must be appended/put to the DOM. Here how it works for me
var content = "<div id='content_dv'>";
content += "<table border='1' style='height:auto;width:auto;'>";
content += "<tr>";
content += "<td>";
content += "This is row 1";
content += "</td>";
content += "</tr>";
content += "<tr>";
content += "<td>";
content += "This is row 2";
content += "</td>";
content += "</tr>";
content += "<tr>";
content += "<td>";
content += "This is row 3";
content += "</td>";
content += "</tr>";
content += "</table>";
content += "</div>";
$("body").append(content);
alert($('#content_dv').html());
Upvotes: 2
Reputation: 8166
Just remove .find('#content_dv')
from your code.
What you're trying to do is to find an element with id content_dv
inside an element with id content_dv
;)
PS Your height and width will be equal to 0, for you've not yet injected your new element into the existing page markup.
Upvotes: 1