Attributes


Attributes

The properties and attributes associated with those elements are some of the most basic elements that can be manipulated in relation to DOM elements.

Most of the attributes can be found as DOM node properties through JavaScript. Some of the most prevalent features are –

  • className
  • tagName
  • id
  • href
  • title
  • rel
  • src

jQuery gives us the means to control the attributes of an element quickly and allows us access to that element to modify its properties as well.

Get Attribute Value

The attr() can set an attribute value from the first element in the corresponding set or set attribute values in all matched items.

Set Attribute Value

You can use the attr(name, value) method to set the named attribute on all elements of the wrapped set with the provided value.

Applying Styles

Apply defined style sheets to every matching element that can utilize the addClass(classes) function. Multiple space-divided classes can be specified.