Js allows you to add and delete Web sites dynamically.

Source: Internet
Author: User
Js instances: & amp; lt; html & amp; gt; & amp; lt; head & amp; gt; & amp; lt; title & amp; gt; php point-by-point-Follow php development and provide professional web development tutorials & amp; lt;/title & amp; gt;

The js instance is as follows:


   Php point-by-point-Follow php development and provide professional web development tutorials  
 Script function add () {var name = document. getElementById ("name "). value; var url = document. getElementById ("url "). value; var list = document. getElementById ("list"); // dynamically create a node var link = document. createElement ("a"); link. setAttribute ("href", url); // sets the link property. innerHTML = name; // Add the delete button var button = document. createElement ("input"); button. setAttribute ("type", "button"); button. value = "delete";/** (1 ). event object indicates the object status Provides details about the object. IE browser is stored in the event attribute of the Window object. (2) The srcElement attribute is a reference to the Window object, Document object, or Element object that generates the event (3). The parentNode attribute returns the parent node of the specified node. (4) The removeChild () method deletes the subnode. **/Button. onclick = function (event) {var target; if (event = null) {target = window. event. srcElement;} else {target = event.tar get;} var div = target. parentNode; div. parentNode. removeChild (div); alert ("deleted successfully");} // Add the generated content var div = document. createElement ("div"); div. appendChild (button); div. insertBefore (link, button); list. appendChild (div);} script Site Name:URL:       

The js instance running result is as follows:

The preceding js Code has been explained in detail. For details about attributes of DOM objects, refer to the manual.

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.