JavaScript tips for deleting the code instance _ javascript of a specified child element

Source: Internet
Author: User
This article mainly introduces the code example for deleting the specified child element in JavaScript. This article provides code examples and implementation code explanations. if you need it, refer to the example for deleting the specified child element in native javascript:

This topic describes how to use native javascript to delete specified child elements.
We all know that it is more convenient to use jquery to implement this function, but it is not difficult to use native javascript. The following is an introduction.
For more information about how jquery can implement this function, see the section "delete subelement code instance" in jquery.

Code example:

The code is as follows:





Foot home

Script
Window. onload = function (){
Var obt = document. getElementById ("bt ");
Var obox = document. getElementById ("box ");
Var lis = obox. getElementsByTagName ("li ");
Obt. onclick = function (){
Obox. removeChild (lis [1]);
}
}
Script



  • Thank you for choosing the best team. only by working hard can we have a bright tomorrow.

  • No one is a master at the beginning. you must work hard.

  • Every day is new, so cherish the time.





The above code implements our requirements. The following describes the implementation process.

Code comment:

1. window. onload = function () {}, when the content of the document is fully loaded, run the code in the function.
2. var obt = document. getElementById ("bt") to get the button element object.
3. var obox = document. getElementById ("box"), get the element object whose id attribute value is box.
4. var lis = obox. getElementsByTagName ("li") to obtain the li element set under the box element.
5. obt. onclick = function () {}, and register the click event processing function for the button.
6. obox. removeChild (lis [1]) to delete the specified child element of the parent element.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.