jquery for the Front-End Learning series

Source: Internet
Author: User
Tags prev

About jquery

Introduction to jquery

Find a specific element, then add a style to it, create a child element, and so on

jquery Basic Selector
    • Id

ID selector: finds the specified element based on the given ID

Grammar

$ ("div");
    • . class

Class Selector: finds the specified element according to the class name

Grammar

$ (". class");
    • Selector1,selector2,selectorn

After merging the elements of each selector to return together, you can specify as many selectors and merge the matched elements into one result

Grammar

$ ("selector1,selector2,selectorn")

HTML code

<Divclass= "notme">Div class= "notme"</Div><Divclass= "myClass">Div class= "myClass"</Div><spanclass= "myClass">Span class= "myClass"</span>

jquery Code

$ (". myClass");

Results

<class= "myClass">div class= "myClass"</Div > <  class= "myClass">span class= "myClass"</span  >
jquery Hierarchy Selector
    • Ancestor descendant

Descendant selector: matches all specified descendant elements under a given parent element (as long as it is included under the parent Element)

Grammar

$ ("ancestor  Descendant")

HTML code

<form>  <label>Name:</label>  <inputname= "name" />  <fieldset>      <label>Newsletter:</label>      <inputname= "newsletter" /> </fieldset></form><inputname= "none" />

jquery Code

$ ("form Input")

Results

<name= "name"/><name= " Newsletter "/>
    • Parent > Child

Child selector: matches all specified child elements under the given parent element (it is different from the background element, look at the code carefully)

Grammar

$ ("parent > Child")

HTML code

<form>  <label>Name:</label>  <inputname= "name" />  <fieldset>      <label>Newsletter:</label>      <inputname= "newsletter" /> </fieldset></form><inputname= "none" />

jquery Code

$ ("form > Input")

Results

<name= "name"/>
    • Prev + Next

Prev Method: matches all next elements immediately following the Prev element

Grammar

$ ("prev + Next")

HTML code

<form>  <label>Name:</label>  <inputname= "name" />  <fieldset>      <label>Newsletter:</label>      <inputname= "newsletter" /> </fieldset></form><inputname= "none" />

jquery Code

$ ("label + Input")

Results

<name= "name"/><name= " Newsletter "/>
    • Prev ~ siblings

Prev method: matches all prev sibling elements

Grammar

$ ("prev ~ Siblings")

HTML code

<form>  <label>Name:</label>  <inputname= "name" />  <fieldset>      <label>Newsletter:</label>      <inputname= "newsletter" /> </fieldset></form><inputname= "none" />

jquery Code

$ ("form ~ Input")

Results

<name= "none"/>

jquery Basic Filter

jquery for the Front-End Learning series

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.