JQuery Prop () method

Source: Internet
Author: User
Keywords jquery prop method jquery method prop



Add and remove attributes that are de-removed as ' color ':



$(‘button‘).click(function () {

  var $x = $(‘div‘)

  $x.prop(‘color‘, ‘f00‘)

  $x.append(‘The color Attributes:‘ + $x.prop(‘color‘))

  $x.removeProp(‘color‘)

})



The prop () method sets or returns the attributes and values of the selected element.



Returns the value of the first matching element when a property value is returned;



When setting property values, set one or more property/value pairs for the matching element collection



Note: 

the prop () method should be used to retrieve property values , such as DOM properties;



To retrieve HTML attributes, use the attr () method instead;



To remove an attribute, use the Removeprop () method





eg:


returns the value of the property : $ (selector). Prop (the name of the specified property)



set properties and Values : $ (selector). Prop (the name of the specified property, the value of the specified property)



use functions to set properties and values : $ (selector). Prop (Specifies the name of the property, function (retrieves the index position of the element in the collection, retrieves the current property value of the selected element))



set multiple properties and values : $ (selector). Prop ({The name of the specified property: The value of the specified property, the name of the specified property: The value of the specified property, ...})



JQuery Prop () method


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.