From the course: jQuery Essential Training

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Manipulating attributes

Manipulating attributes - jQuery Tutorial

From the course: jQuery Essential Training

Start my 1-month free trial

Manipulating attributes

- [Teacher] Just as there are functions for manipulating the content of documents inside elements in text, there are also functions for manipulating attributes. Here, on the jQuery website, let's click on the API documentation, and then click on Attributes. So there are two functions, attr and removeAttr, which are used to operate on attributes. The attr function is used to read the value of an attribute, and if the attribute is not present on an element, then the result is undefined. When called with both an attribute name and a value, an attribute with that value is set on the element. And removeAttr does what you'd expect, which is remove the named attribute from an element. So, let's exercise these in the code. In your editor, let's go ahead and open up the attributes_start file, and this is where we'll exercise some of the code, so let me just go ahead and bring this up in the browser so you can see it before I get started. And you can see, in this example, I've got my example…

Contents