attr() Method


The attr() method is used to get or set attributes of HTML elements.

Attributes include src, href, title, alt, placeholder, and more.

This method is commonly used to change images, links, and input attributes dynamically.

This retrieves the value of the href attribute.

This updates the attribute value dynamically.

This changes the image source without reloading the page.

attr() Method Notes:

  • Gets or sets attributes
  • Useful for dynamic content
  • Common with images and links
  • Works on all HTML elements