From jQuery JavaScript Library
(Redirected from
DOM/Attributes)
Reading and Writing Attributes:| Name | Type |
| attr( name ) | Returns: Object |
| Access a property on the first matched element. This method makes it easy to retrieve a property value from the first matched element. If the element does not have an attribute with such a name, undefined is returned. Attributes include title, alt, src, href, width, style, etc. |
| attr( properties ) | Returns: jQuery |
| Set a key/value object as properties to all matched elements. |
| attr( key, value ) | Returns: jQuery |
| Set a single property to a value, on all matched elements. |
| attr( key, fn ) | Returns: jQuery |
| Set a single property to a computed value, on all matched elements. |
Class:| Name | Type |
| addClass( class ) | Returns: jQuery |
| Adds the specified class(es) to each of the set of matched elements. |
| removeClass( class ) | Returns: jQuery |
| Removes all or the specified class(es) from the set of matched elements. |
| toggleClass( class ) | Returns: jQuery |
| Adds the specified class if it is not present, removes the specified class if it is present. |
| toggleClass( class, switch ) | Returns: jQuery |
| New in jQuery 1.3 Adds the specified class if the switch is true, removes the specified class if the switch is false. |
Html:| Name | Type |
| html( ) | Returns: String |
| Get the html contents (innerHTML) of the first matched element. This property is not available on XML documents (although it will work for XHTML documents). |
| html( val ) | Returns: jQuery |
| Set the html contents of every matched element. This property is not available on XML documents (although it will work for XHTML documents). |
Text:| Name | Type |
| text( ) | Returns: String |
| Get the combined text contents of all matched elements. |
| text( val ) | Returns: jQuery |
| Set the text contents of all matched elements. |
Value:| Name | Type |
| val( ) | Returns: String, Array |
| Get the input value of the first matched element. |
| val( val ) | Returns: jQuery |
| Set the value attribute of every matched element. |
| val( val ) | Returns: jQuery |
| Checks, or selects, all the radio buttons, checkboxes, and select options that match the set of values. |