JQuery - how to get attribute value example

By Hardik Savani | April 14, 2016 | Category : Javascript jQuery

If you are new and you want to get attribute value then you can get easily. sometime maybe we also need to get custom attribute value, i mean data attribute value. In following example i give you three way to get custom attribute value in jquery.


<html lang="en">


<title>Get Custom Attribute Value</title>

<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>



<a href="example.com" data-id="1" myname="hd">Example</a>

<script type="text/javascript">

var a_href = $("a").attr("href");


var a_data_id = $("a").data("id");


var a_myname = $("a").attr("myname");





Hardik Savani
My name is Hardik Savani. I'm a full-stack developer, entrepreneur and owner of Aatman Infotech. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.
Follow Me: Github Twitter
***Do you want me hire for your Project Work? Then Contact US.