Home > Article > Web Front-end > How to delete div tag in javascript
How to delete div tags in javascript: Use the [removeChild()] method to delete a node from the child node list, the code is [_li.parentNode.removeChild(_li)].
The operating environment of this tutorial: Windows 7 system, JavaScript version 1.8.5, DELL G3 computer.
Javascript method to delete div tags:
childNodes: Returns a NodeList containing all types of child nodes of the selected node. (Note: Elements in spaces are regarded as text, and text is also regarded as node #text)
removeChild(): Method can delete a node from the child node list. If the deletion is successful, this method can return the deleted node, if it fails, it returns NULL.
Example:
<li id="_li"> <a href="#"> <h4 align="center">hh</h4> </a> <div class="xx"> <div id="a"> <p>姓名:</p> <p>年龄:</p> </div> </div> </li>
Delete the entire 25edfb22a4f469ecb59f1190150159c6 tag
var _li=document.getElementById("_li"); _li.parentNode.removeChild(_li);//删除整个li
Delete the entire 3499910bf9dac5ae3c52d5ede7383485 tag inside the 25edfb22a4f469ecb59f1190150159c6. Personally I feel bad about this childNodes attribute. Use it, it contains too many miscellaneous tags
var _li=document.getElementById("_li"); _li.removeChild(_li.childNodes[1]);
Related free learning recommendations: javascript video tutorial
The above is the detailed content of How to delete div tag in javascript. For more information, please follow other related articles on the PHP Chinese website!