Considerations for the jquery selector Hollow grid

Source: Internet
Author: User

First, explain what the selector means by using a space, and if the two elements in the selector are separated by a space, the descendant elements of the previous element are represented. For example, $ (' Div:hidden '), which represents all the hidden elements in the div, this hidden element can be a child element of a div, or it can be a child of a div child element. If there is no space in the selector, it represents a and the relationship, if you say $ (' Div:hidden '), represents all the hidden Div, this is not related to the level of the elements!

Let's look at an example: the HTML code section
<div>
<div style= "Display:none;" >aa</div>
<div style= "Display:none;" >bb</div>
<div style= "Display:none;" >cc</div>
<div style= "Display:none;" >dd</div>
</div>
<div style= "Display:none;" >ee</div>
<div style= "Display:none;" >ff</div>

jquery section

var $ta = $ ('. Test:hidden '); A selector with a space represents all the hidden elements in the element with class test, and obviously the result is all the elements in the first Div.
var $TB = $ ('. Test:hidden '); A selector without a space that represents class test and is a hidden element, which refers to the last two Div and the final child element in the first Div
Alert ($ta. length); Output is 4
Alert ($tb. length); Output is 3

jquery Selector Hollow lattice problem can not be ignored, so in the development process must be clear ideas to see if you need to add space.

Summarize

There are two jquery expressions

$ (". Active:hidden") a selector with a space that represents the descendant selector and selects all hidden child objects within the style active.

$ (". Active:hidden") selector with no space, representing a filter, selecting an object with style active and hidden.

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.