06jquery-02-Hierarchy Selector

Source: Internet
Author: User
Tags lua

Because the DOM structure is hierarchical, we often make choices based on hierarchical relationships.
1. Level selector $ (' ancestor descendant '), select descendants in Ancestors, middle spaces:
 
   
  
  1. $(‘form[name=upload] input‘);
  2. //选择name属性为upload的表单里的<input>

Multi-layer selection is also allowed:
 
   
  
  1. $(‘form.test p input‘); // 在form表单选择被<p>包含的<input>

2, sub-selector $ (' parent>child '), similar to the hierarchy selector, butqualifying the hierarchy relationship must be a parent-child relationship, that is, the <child> node must be the immediate child node of the <parent> node.
  
 
  1. <!-- HTML结构 -->
  2. <div class="testing">
  3. <ul class="lang">
  4. <li class="lang-javascript">JavaScript</li>
  5. <li class="lang-python">Python</li>
  6. <li class="lang-lua">Lua</li>
  7. </ul>
  8. </div>
  9. //jQuery选择器
  10. $(‘ul.lang>li.lang-javascript‘); // 可以选出[<li class="lang-javascript">JavaScript</li>]
  11. $(‘div.testing>li.lang-javascript‘); // [], 无法选出,因为<div>和<li>不构成父子关系

3, filter filter is generally not used alone, it is usually attached to the selector, help us to more precisely locate the element. Observe the effect of the filter:
  
 
  1. $(‘ul.lang li‘); // 选出JavaScript、Python和Lua 3个节点
  2. $(‘ul.lang li:first-child‘); // 仅选出JavaScript
  3. $(‘ul.lang li:last-child‘); // 仅选出Lua
  4. $(‘ul.lang li:nth-child(2)‘); // 选出第N个元素,N从1开始
  5. $(‘ul.lang li:nth-child(even)‘); // 选出序号为偶数的元素
  6. $(‘ul.lang li:nth-child(odd)‘); // 选出序号为奇数的元素

4. Form Selector : InputYou can choose <input>,<textarea>,<select> and <button>
: FileYou can choose <input type= "file", as in Input[type=file]
: CheckBoxYou can select the check box, as with Input[type=checkbox]
: RadioYou can choose a radio box, as with Input[type=radio]
: FocusYou can select elements of the current input focus, such as placing the cursor on a <input>, with $ (' Input:focus ') to choose
: CheckedSelect the checkbox and check box on the current tick and use this selector to instantly get the item that the user has selected, such as $ (' input[type=radio]:checked ')
: EnabledYou can select <input>, <select>, which can be entered normally.and so on, that is, no gray input.
:d isabledAnd: Enabled just the opposite, select those that cannot be entered.
: VisibleAll the visible
: HiddenAll the Hidden

06jquery-02-Hierarchy Selector

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.