JS code-style chain structure

Source: Internet
Author: User

<div class= "box" >
<ul class= "Menu" >
<li class= "Level1" >
<a href= "#none" > Shirts </a>
<ul class= "Level2" >
<li><a href= "#none" > Short sleeve Shirts </a></li>
<li><a href= "#none" > Long-sleeved shirts </a></li>
<li><a href= "#none" > Short sleeve T blood </a></li>
<li><a href= "#none" > Long sleeves T-blood </a></li>
</ul>
</li>
<li class= "Level1" >
<a href= "#none" > Sweatshirt </a>
<ul class= "Level2" >
<li><a href= "#none" > Sweatshirt 1</a></li>
<li><a href= "#none" > Sweatshirt 2</a></li>
<li><a href= "#none" > Sweatshirt 3</a></li>
<li><a href= "#none" > Sweatshirt 4</a></li>
</ul>
</li>
<li class= "Level1" >
<a href= "#none" > Trousers </a>
<ul class= "Level2" >
<li><a href= "#none" > Pants 1</a></li>
<li><a href= "#none" > Pants 2</a></li>
<li><a href= "#none" > Pants 3</a></li>
<li><a href= "#none" > Pants 4</a></li>
</ul>
</li>
</ul>
</div>

<script>
$ (". Level1>a"). Click (function () {
$ (this). AddClass ("current")
. Next (). Show ()
. Parent (). siblings (). Children ("a"). Removeclass ("current")
. Next (). Hide ();
return false;
});
</script>

<!--
[Email protected]
Date: 2017-07-02
Description: (1) No more than 3 operations for the same object can be written in one line,
such as: $ ("Li"). Show (). Unbind ("click");
(2) For more operations on the same object, it is recommended that each line write a
such as: $ (this). Removeclass ("mouse")
. addclass ("Cat")
. Stop ()
. FadeTo ("Fast", 0.6)
. FadeTo ("Fast", 1)
. Unbind ("click")
. Click (function () {
To do
});
(3) A few operations on multiple objects, you can write one line per object, if there are child elements, you can indent
such as: $ (this). Removeclass ("mouse")
. addclass ("Cat")
. Childer ("Li"). Show (). End ()
. siblings (). Removeclass ("over")
. Childer (). Hide ();
-

JS code-style chain structure

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.