Jquery operation css Selector

Source: Internet
Author: User
Jquery operation css selector. addClass ()
Add the specified style class name for each Matching Element
. AddClass (className)
ClassName adds one or more style names for each matching element.
. AddClass (function (index, currentClass ))
The function returns one or more values separated by spaces. index indicates the index position in the Parameter Match. this indicates the current element in the matched element set.
$ ("P"). addClass ("myClass yourClass"); add these two class name styles to the element p.
$ ("Ul li: last"). addClass (function (index ){
Return "item-" + index;
}) In the last
  • Add the "item-1" style to the element.


    . CSS ()
    Obtains the calculation value of the style attribute of the first element in the matched element set or sets one or more matching elements.
    Css attributes.

    . Css (PRopertyName)
    PropertyName: Specifies a css attribute name. An array composed of one or more css attributes.
    Background (this).css ("background-color"); gets the background color of the current element.
    ((This).css (["width", "height", color]) to obtain the font color of the current element.

    . Css (propertyName, value)
    PropertyName: Specifies a css attribute name.
    Set the css attribute value.
    . Css (propertyName, function)
    PropertyName: Specifies a css attribute name.
    Function is a function used to return the set value. This is the current element.

    Detail ('p.example'detail .css ('width', function (index ){
    Return index * 50;
    }) Set the width of a matching element to a greater value.
    $ ("P"). mouSEOver (function (){
    ((This).css ("color", "red ");
    }) The text turns red when the mouse passes through the p element.
    $ ("# Box"). one ("click", function (){
    ((This).css ("width", "+ = 200 ")
    }) Increase # The box width to 200 pixels.


    . HasClass ()
    Determine whether any matching element is assigned to a given (Style Class)
    . HasClass (className)
    The name of the style to be queried by className.
    $ ("# Myp"). hasClass ("foo") indicates whether the matching element contains the foo style.
    If this style exists, true is returned. If not, false is returned.


    . RemoveClass ()
    Remove the style above the matching element.
    . RemoveClass ([className])
    One or more style names removed from each matching element are separated by spaces.
    $ ("P"). removeClass ("myClass yourClass ")
    . RemoveClass (function (index, class ))
    A function returns one or more elements to be removed, and the current elements in all matched element sets of the index.


    . ToggleClass ()
    Change the style name for each element in the matched element set.
    . ToggleClass (className)
    ClassName is one or more (separated by spaces) style class names that are used to switch between each element in the matched element set.
    . ToggleClass (className, switch)
    Switch is a Boolean value used to determine whether a style should be added or removed.
    . ToggleClass ([switch])
    Switch: A boolean value used to determine whether to add or remove a style day.

    $ ('# Foo'). toggleClass (className, add0rRemove) is equivalent
    If (add0rRemove ){
    $ ('# Foo'). addClass (className );
    } Else {
    $ ('# Foo'). removeClass (className)
    }

    $ ("P"). click (function (){
    $ (This). toggleClass ("highlight ");
    // Switch the style when you click the current p label.
    })

    The above is the content for jquery to operate the css selector. For more related articles, please follow the PHP Chinese Network (www.php1.cn )!

  • Related Article

    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.