I'm trying to create table elements using jQuery but it won't return the first element stored or created:
$("<tr>",{class: "ertert"}).append($("<td>",{text:"adfsadfasdf"})).html()
// "<td>adfsadfasdf</td>"
What happened to the <tr>
?
I'm trying to create table elements using jQuery but it won't return the first element stored or created:
$("<tr>",{class: "ertert"}).append($("<td>",{text:"adfsadfasdf"})).html()
// "<td>adfsadfasdf</td>"
What happened to the <tr>
?
try this code: HTML:
<table class="parent"></table>
JS:
$('.parent').html('<tr class="name"><td>anything</td></tr>');
if you do not want to replace use this to add:
$('.parent').append('<tr class="name"><td>anything</td></tr>');
When chaining it with html()
method at the end, it only returns outer HTML for the <tr>
. You have not assigned <tr>
to any of variable & nor you have added it to DOM yet, hence it is no longer accessible. You have lost it in the local scope.
If you use a variable such that
var $tr = $("<tr>",{class: "ertert"});
$tr.append($("<td>",{text:"adfsadfasdf"})).html()
You will be able to access it again.