# jQuery website jQuery documentation

## DOM

### attr(String name) : Object

name | String | The name of the property to access.

Access a property on the first matched element. This method makes it easy to retrieve a property value from the first matched element.

#### Example

##### Before

    <img src="test.jpg"/>

##### Code

    $("img").attr("src");

##### Result

    test.jpg

### attr(Hash prop) : jQuery

prop | Hash | A set of key/value pairs to set as object properties.

Set a hash of key/value object properties to all matched elements. This serves as the best way to set a large number of properties on all matched elements.

#### Example

##### Before

    <img/>

##### Code

    $("img").attr({ src: "test.jpg", alt: "Test Image" });

##### Result

    <img src="test.jpg" alt="Test Image"/>

### attr(String key, Object value) : jQuery

key | String | The name of the property to set.
value | Object | The value to set the property to.

Set a single property to a value, on all matched elements.

Note that you can't set the name property of input elements in IE. Use $(html) or $().append(html) or $().html(html) to create elements on the fly including the name property.

#### Example

##### Before

    <img/>

##### Code

    $("img").attr("src","test.jpg");

##### Result

    <img src="test.jpg"/>

### text() : String

Retrieve the text contents of all matched elements. The result is a string that contains the combined text contents of all matched elements. This method works on both HTML and XML documents.

#### Example

##### Before

    <p>Test Paragraph.</p>

##### Code

    $("p").text();

##### Result

    Test Paragraph.

### removeAttr(String name) : jQuery

name | String | The name of the attribute to remove.

Remove an attribute from each of the matched elements.

#### Example

##### Before

    <input disabled="disabled"/>

##### Code

    $("input").removeAttr("disabled")

##### Result

    <input/>

### addClass(String class) : jQuery

class | String | A CSS class to add to the elements

Adds the specified class to each of the set of matched elements.

#### Example

##### Before

    <p>Hello</p>

##### Code

    $("p").addClass("selected")

##### Result

    [ <p class="selected">Hello</p> ]

### removeClass(String class) : jQuery

class | String | A CSS class to remove from the elements

Removes the specified class from the set of matched elements.

#### Example

##### Before

    <p class="selected">Hello</p>

##### Code

    $("p").removeClass("selected")

##### Result

    [ <p>Hello</p> ]

### toggleClass(String class) : jQuery

class | String | A CSS class with which to toggle the elements

Adds the specified class if it is not present, removes it if it is present.

#### Example

##### Before

    <p>Hello</p><p class="selected">Hello Again</p>

##### Code

    $("p").toggleClass("selected")

##### Result

    [ <p class="selected">Hello</p>, <p>Hello Again</p> ]