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

Hello,

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,

Richi

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

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 became a Liaison between Arvixe and Clip-Bucket, so I am here to assist you with anything you need regarding Clip-Bucket or any particular computer-related subject you need. Best Regards, Richi

Leave a Reply

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


+ 4 = 8

You may use these HTML tags and attributes: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>