Documentation

API/1.1.2/Attributes

From jQuery JavaScript Library

(Redirected from DOM/Attributes)
Jump to: navigation, search

This is an old version of the Attributes API:
View the Current API

NameType
Reading and Writing Attributes:

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

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

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 input value of the first matched element.
val( val )Returns: jQuery
Set the value attribute of every matched element.
[[Attributes/val#[val]|val( [val] )]]Returns: jQuery
Checks, or selects, all the radio buttons, checkboxes, and select options that match the set of values. Must be an array for radio buttons or multi-selects.