jquery Add Delete Dom element

Source: Internet
Author: User

1. Add DOM element append prepend before after

Append add a previous instance of the sibling element:

<div class= "header" ><p> add node after sibling element </p></div>

var pageup = ' <strong>append after the sibling element </strong><br> ';
$ ('. Header '). On (' click ', function () {
$ (this). Append (PageUp);
});


Prepend add an instance after the sibling element:

<div class= "section" ><p> add node element before sibling </p></div>

var pagedown = ' <strong>prepend before the sibling element </strong><br> '
$ ('. section '). On (' click ', function () {
$ (this). Prepend (PageDown);
});



Before add a node to the front of the selected element

var home = ' <p>before added before the specified element </p> ';

$ ('. Footer '). On (' click ', function () {
$ ('. Footer>strong '). before (home);
});

After adds a node after the element that is selected

var end = ' <p>after added after the specified element </p> '
$ ('. aside '). On (' click ', function () {
$ ('. Aside>strong '). After (end);
});

2. Remove the DOM element remove (delete) empty (empty)

Use Remove to delete a node

$ ('. Top '). On (' click ', function () {
$ (this). Remove ();
});

Emptying a node with empty

<div class= "Bottom" >
<p> Mouse out empty node </p>
<p> Mouse out empty node </p>
<p> Mouse out empty node </p>
<p> Mouse out empty node </p>
<p> Mouse out empty node </p>
</div>

$ ('. Bottom '). On (' click ', function () {
$ (this). empty ();
});

3. Selection of nodes

Chilren Select all child nodes
Parent Selects parents
Next Next node Nextall selects all subsequent elements
Prev Previous node Prevall selects all previous elements
Siblings filters out all sibling nodes, except for the current selected node

Closest quickly select parent node

Two levels of menu creation

<ul class= "List" >
<li>
<a href= "javascript:;" > Menu 1</a>
<nav>
<a href= "javascript:;" > Sub-menu 1</a>
<a href= "javascript:;" > Sub-menu 1</a>
<a href= "javascript:;" > Sub-menu 1</a>
</nav>
</li>
<li>
<a href= "javascript:;" > Menu 2</a>
<nav>
<a href= "javascript:;" > Sub-menu 2</a>
<a href= "javascript:;" > Sub-menu 2</a>
<a href= "javascript:;" > Sub-menu 2</a>
</nav>
</li>
<li>
<a href= "javascript:;" > Menu 3</a>
<nav>
<a href= "javascript:;" > Sub-menu 3</a>
<a href= "javascript:;" > Sub-menu 3</a>
<a href= "javascript:;" > Sub-menu 3</a>
</nav>
</li>
</ul>


var ListA = $ (' ul.list>li>a ');
Lista.next (). Hide ();
Lista.on (' click ', function () {
$ (this). Next (). Slidedown (). Parent (). siblings (). Children (). Next (). Slideup (1000);
$ (this). Next (). Show (). Parent (). siblings (). Children (). Next (). Hide ();
});
$ (' Ul.list>li '). On (' Blur ', function () {
Lista.next (). Hide ();
Console.log (' Lost Focus ');
});
})

jquery Add Delete Dom 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.