Home > Web Front-end > JS Tutorial > How to delete div tag in javascript

How to delete div tag in javascript

coldplay.xixi
Release: 2023-01-04 09:35:43
Original
8160 people have browsed it

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)].

How to delete div tag in javascript

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>
Copy after login

Delete the entire

  • tag

                                 var _li=document.getElementById("_li");
                                _li.parentNode.removeChild(_li);//删除整个li
    Copy after login

    Delete the entire tag inside the

  • . 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]);
    Copy after login

    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!

  • Related labels:
    source:php.cn
    Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
    Popular Tutorials
    More>
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template