I have a problem removing a row with JavaScript, since it does not have a class nor an ID, I can not reference it with CSS.
The row I'd like to eliminate begins with the text: Post
Hope someone can help
I have a problem removing a row with JavaScript, since it does not have a class nor an ID, I can not reference it with CSS.
The row I'd like to eliminate begins with the text: Post
Hope someone can help
This does it:
var rows = document.getElementById('theTable').rows;
for (var i = 0; i < rows.length; i++) {
if ( rows[i].firstElementChild.textContent.trim().split(' ')[0] === 'Post' ) {
rows[i].parentNode.removeChild(rows[i]);
}
}
Note: trim() and what not does not work in IE8. You can leave it out, but then you have to make sure that there is no leading white-space before the word "Post".
Live demo: http://jsfiddle.net/simevidas/xn6U8/
Update:
var rows = document.getElementsByClassName('basket')[0].rows;
for (var i = 0; i < rows.length; i++) {
if ( rows[i].cells[0].textContent.trim().split(' ')[0] === 'Post' ) {
rows[i].parentNode.removeChild(rows[i]);
}
}
Live demo: http://jsfiddle.net/simevidas/A73PK/2/
getElementById to select it. Your table does not have an ID. You have to either define an ID, or use another means to select the table element. But my code works for your table. See here: jsfiddle.net/simevidas/A73PKfirstElementChild and textContent aren't supported in IE before IE9. For firstElementChild, you can use .cells[0] instead to get the first cell in the row.