I decleared a <table>
inside my JSP page. Using JavaScript, I want to delete all <tr>
s whose id
contains ;
.
For example:
<tr id=";1234;">
...
...
</tr>
The entire line must be deleted. Someone can give me a tip?
I decleared a <table>
inside my JSP page. Using JavaScript, I want to delete all <tr>
s whose id
contains ;
.
For example:
<tr id=";1234;">
...
...
</tr>
The entire line must be deleted. Someone can give me a tip?
document.querySelectorAll('tr[id*=";"]').forEach(node => node.remove());
<table>
<tr id=";1234;">
<td>Remove Me</td>
</tr>
<tr>
<td>Keep Me</td>
</tr>
</table>
You can programmatically remove all <tr>
elements with an id
containing a ;
by executing the following snippet:
Array.from(document.querySelectorAll('tr[id*=";"]')).forEach(tr => {
tr.remove()
})
Following links for reference:
The EASIEST way to do this is as follows AND is cross-browser (non-ECMA6) compatible.
https://jsfiddle.net/dfju8xn8/1/
<table>
<tr id=";1234;">
<td>foo</td>
</tr>
<tr id="yadayada">
<td>moo</td>
</tr>
</table>
and Javascript
var myElements = document.querySelectorAll('tr[id*=";"]');
for (var xx = 0; xx < myElements.length; xx++) {
myElements[xx].outerHTML ='';
}
p.s. For readability sake, you should use one of the methods above. If you are going to have to iterate over a large result set, consider that for loops are tested as executing faster.