How to get attribute value in JQuery

Share Me
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

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.

About code chef

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by code chef →