jquery - Insert Row(child) in table using JavaScript -


i have table containing 4 main rows , 1 (expand or collapse) button.on click of (expand or collapse) button want insert 1 more row in middle of rows(which result in total 8 rows) iterating table rows.how using javascript?see image below.any suggestion.

enter image description here

this code have return on click of expand or collapse button,

  jquery('#btnid').click(function() {             var = this;             $("#example tbody tr").each(function(i) {                                    //what code need add here             });         }); 

due fact, haven't provided code example, can suggest 1 way achieve this.

you can determine row above row you'll want insert id on tr or css selector :nth-of-type(4) example.

after that, can use row jquery element (example: $("tr#yourrow")) , append row after using append().

example: $("tr#yourrow").append("<tr>... row definition ...</tr>")

based on updated question:

jquery('#btnid').click(function() {     var = this;     $("#example tbody tr").each(function(i, object) {                            $(object).after("<tr>... row definition ...</tr>")     }); }); 

the row definition should done yourself. don't know logic behind iteration in case. think you'll it. :)


Comments

Popular posts from this blog

c# - Where does the .ToList() go in LINQ query result -

Listeners to visualise results of load test in JMeter -

php - Click a button with XPath using an id from the same row -