How to Get the Value of an Element’s Attribute with jQuery using attr()


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.

Best Regards,


Owner of Juapo2Services

Looking for quality web hosting? Look no further than Arvixe Web Hosting!

Tags: , , , , , , , , , , , | Posted under Programming/Coding | RSS 2.0

Author Spotlight

Richi González

I started programming when I was 12. I'm a Developer and have been working with the Clip-Bucket script since it came out. I'm the Liaison between Arvixe and Clip-Bucket, so anything you need regarding Clip-Bucket or any particular computer-related subject you need, let me know so I can assist you.

Leave a Reply

Your email address will not be published. Required fields are marked *