property values for JQuery operand objects

Source: Internet
Author: User

Using jquery to manipulate foreground objects (Div,span ... ) is a very common thing, this article simply introduces several operational scenarios.

1): Get object by property value

2): Use jquery to modify the object's property values

3): Gets and modifies the property value of the object's style

 



1: Getting an object from a property value

The basic structure is: Object Category [Property name = ' property value ']. Example: span[title= ' First_span ')

<script type= "Text/javascript" >    function Getobjvaluebytitle () {        var obj = $ ("#first_div span[title=" First_span '] ");        Alert (Obj.text ());    } </script>

2: Modifying property values of an object

Using the attr method provided by jquery, the basic structure for getting property values is: $ (obj). attr ("property name"); the structure of the modified property value is: $ (obj). attr ("attribute name", "property value");

<script type= "Text/javascript" >    function Changeobjattrvalue () {        var Objs = $ ("#first_div. MySpan");        $.each (OBJS, function (index, item) {            $ (item). attr ("title", "haha");            Alert ($ (this). attr ("Nodeurl"));  $ (this) = = $ (item)        });    } </script>

Note: For specific objects we can arbitrarily add our own custom properties, and we can get the corresponding property values through a custom property name, such as the nodeurl in this article. 】

3: Get and modify the object's Style property value

The CSS method provided by jquery is used to get the structure of a property in the style: $ (obj). CSS ("property name"); the structure of the modified property value is: $ (obj). CSS ("Property name", "attribute value");

<script type= "Text/javascript" >    function Changeobjstylevalue () {        var Objs = $ ("#first_div span");        Objs.each (function (index, item) {            $ (item). CSS ("Color", "blue");        });    </script>

By the comparison between the second and the third we can simply summarize: the property value of the operand (ID, name, title ...). We can use jquery's attr method; Manipulate the object's Style property (Background,color,width,height in CSS ...). We can use jquery's CSS method.

When we use jquery to facilitate the collection, we can use each method, each of the two forms of the monetization:

1): $.each (OBJS, function (index, item) {...});

2): Objs.each (function (index, item) {...});

property values for JQuery operand objects

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.