jQuery: The Write Less, Do More JavaScript Library

API/1.2/Attributes

From jQuery JavaScript Library

(Redirected from Attributes)
Jump to: navigation, search

NameType
Attr:

NameType
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.
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.
removeAttr( name ) Returns: jQuery
Remove an attribute from each of the matched elements.
Class:

NameType
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.
HTML:

NameType
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:

NameType
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:

NameType
val( ) Returns: String, Array
Get the content of the value attribute 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.