Reputation: 1067
Here is the example -
tr = $('<tr>');
row = $('.addNewRow');
tr.html(utils.tmpl("row_tmpl", marginDetails)); //returning some html content
(tr.html()).insertBefore(row);
I want to insert the tr.html() content before the row. But when i am doing so it is throwing error "TypeError: tr.html(...).insertBefore is not a function". Please guide me with this.
Upvotes: 0
Views: 96
Reputation: 1133
You are just missing $
which is causing this issue.
We can achieve your objective using somewhat simple code block also, corresponding JS fiddle is @ http://jsfiddle.net/ZVf48/5/, let me know if you need any clarification here.
Upvotes: 0
Reputation: 133423
As tr
and row
are already jQuery object. just use them
tr = $('<tr>');
row = $('.addNewRow');
tr.insertBefore(row);
Alternatively, You can also use .before()
row.before(tr)
Upvotes: 1
Reputation: 85575
You are missing $ sign:
$(tr.html()).insertBefore(row);
But I this will be fine to do:
tr.insertBefore(row);
As tr contains the html() already.
Upvotes: 0