How to Get the Value of an Element’s Attribute with jQuery using attr()
Written by Richi González Wednesday, 13 February 2013
Lately that I’ve been working a lot with jQuery, I have noticed how easy and small functions get endless possibilities for improving code. In this article, you will learn how to get the value of any attribute of an element with jQuery using attr()
We will imagine we have the following HTML code:
<a class='ourlink' href='#' besthosting='Arvixe'>The Best Hosting</a>
You can notice that we have an attribute called besthosting with Arvixe as its value. To get that value with jQuery, we would run the following code.
var attribute = $('.ourlink').attr('besthosting');alert(attribute); //This would alert "Arvixe"
That’s it! If you have any questions, comments, or suggestions, please do not hesitate to contact me and I’ll be more than glad to assist you.
Owner of Juapo2Services
Looking for quality web hosting? Look no further than Arvixe Web Hosting!