jQuery .remove() not removing -


i want delete table element. not dom. string jquery element. here code:

var content = $('<table cellspacing="0" cellpadding="0" border="0" class="testclass"><tbody><tr><td>test</td></tr></tbody></table>'); content.each(function(){     $(this).remove(); }); console.log(content.prop('outerhtml')); 

jquery can remove if there more 1 table. example 2 or 3. , last 1 still. when there 1 table left in string, .remove() function not working @ all. there still 1 final element cannot removed. last one. need 0 elements example.

not sure you're trying do, question isn't clear, made sample quickly.

js bin

function removetable(table){ $(table).remove();  } 

html:

<table id="table1" >   <tr>     <td>table 1</td><td><button onclick="removetable('#table1');" >delete</button></td>   </tr>   </table>   <table id="table2" >   <tr>     <td>table 2</td><td><button onclick="removetable('#table2');" >delete</button></td>   </tr>   </table>   <table id="table3" >   <tr>     <td>table 3</td><td><button onclick="removetable('#table3');" >delete</button></td>   </tr>   </table>   <table id="table4" >   <tr>     <td>table 4</td><td><button onclick="removetable('#table4');" >delete</button></td>   </tr>   </table> 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -