Featured Post

Jquery .attr()

.attr(attributeName)
Get the value of an attribute for the first element in the set of matched elements.
.attr(attributeName, value)
Set one or more attributes for the set of matched elements.
Returns: String
.attr(attributeName)
attributeName The name of the attribute to get.
Get the value of an attribute for the first element in the set of matched elements.
The .attr() method gets the attribute value for only the first element in the matched set. To get the value for each element individually, use a looping construct such as jQuery's .each() or .map() method.

As of jQuery 1.6, the .attr() method returns undefined for attributes that have not been set. In addition, .attr() should not be used on plain objects, arrays, the window, or the document. To retrieve and change DOM properties, use the .prop() method.

Using jQuery's .attr() method to get the value of an element's attribute has two main benefits:

Convenience: It can be called directly on a jQuery object and chained to other jQuery methods.
Cross-browser consistency: The values of some attributes are reported inconsistently across browsers, and even across versions of a single browser. The .attr() method reduces such inconsistencies.
Example Demo
Find the title attribute of the first in the page.








Once there was a large dinosaur...



The title of the emphasis is:



Comments

Popular posts from this blog

[Inside AdSense] Understanding your eCPM (effective cost per thousand impress...