简体   繁体   中英

Remove table row using javascript not working in IE

remove () doesn't work in IE11. Please provide any solution to the code below.

var TD1= document.getElementById('firstTbl').
        getElementsByTagName('tr')[0].getElementsByTagName('td')[4]; 
//This remove is not working in IE. 
firstTD1.remove();

HTML Code:

<table id="firstTbl">
<tr>
<td> <div class="stylediv">Basic </div> </td>                                      
<td> <div class="stylediv">Critical </div> </td>
<td> <div class="stylediv">Surgical </div> </td>
<td> <div class="stylediv">Hospital </div> </td>                
<td> <div class="stylediv">Waiver </div> </td>                        
</tr>                       
</table>

Note: Goal is to hide Waiver table row.

See below code snippet: working fine in IE and safari

 <html> <table id="firstTbl"> <tr> <td> <div class="stylediv">Basic </div> </td> <td> <div class="stylediv">Critical </div> </td> <td> <div class="stylediv">Surgical </div> </td> <td> <div class="stylediv">Hospital </div> </td> <td> <div class="stylediv">Waiver </div> </td> </tr> </table> <script> var TD1= document.getElementById('firstTbl').getElementsByTagName('tr')[0].getElementsByTagName('td')[4]; //This remove is not working in IE. console.log(TD1.parentNode); TD1.parentNode.removeChild(document.getElementsByTagName('td')[4]); </script> </html> 

Method remove is not supported in all browsers:

Instead remove the element as follows:

var TD1 = document.getElementById('firstTbl').getElementsByTagName('tr')[0].getElementsByTagName('td')[4]; 

TD1.parentNode.removeChild(TD1);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM