Today now in this post i will show you How to get attribute value in JQuery. If you are new and if you want to get the attribute value then i hope you can get this easily. Sometime maybe you also need to get the custom attribute value, here i mean that data attribute value. So now in the following example i will give you three way to get the custom attribute value in jquery.
Example:
<html lang="en">
<head>
<title>Get Custom Attribute Value</title>
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
</head>
<body>
<a href="example.com" data-id="1" myname="hd">Example</a>
<script type="text/javascript">
var a_href = $("a").attr("href");
alert(a_href);
var a_data_id = $("a").data("id");
alert(a_data_id);
var a_myname = $("a").attr("myname");
alert(a_myname);
</script>
</body>
</html>
Read Also : How to convert Object into Array in PHP?
Thanks for read. I hope it help you. For more you can follow us on facebook.