The attr()
method in jQuery can be used to set a new attribute value of an element.
$(selector).attr(attribute, newValue)
attribute
: This is the name of the attribute whose value has to be changed.newValue
: This is the value to be set.In HTML:
In JavaScript:
$("a")
, to select the anchor element. We use the attr()
function to set a new value to the href
attribute.