Neha Gupta
Neha Gupta

Reputation: 1067

How to insert tr.html() content before other tr tag

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

Answers (4)

Siva
Siva

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

Satpal
Satpal

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

Bhojendra Rauniyar
Bhojendra Rauniyar

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

Balachandran
Balachandran

Reputation: 9637

missed $ selector

 $(tr.html()).insertBefore(row);

Upvotes: 0

Related Questions