Skip to content

Instantly share code, notes, and snippets.

@enopanen
Created December 3, 2013 18:05
Show Gist options
  • Save enopanen/7774302 to your computer and use it in GitHub Desktop.
Save enopanen/7774302 to your computer and use it in GitHub Desktop.
This property is relatively straightforward but I always see these problems in StackOverflow. You can pull the .attr() method on any HTML element and pass in the attribute string value. This will return the value of that attribute, whether it’s ID or class or name or maxlength. All HTML attributes may be accessed through this syntax and so it’s …
var alink = $("a#user").attr("href"); // obtain href attribute value
$("a#user").attr("href", "http://www.google.com/"); // set the href attribute to a new value
$("a#user").attr({
alt: "the classiest search engine",
href: "http://www.google.com/"
}); // set more than one attribute to new values
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment