How to Get Attribute Value in JQuery?

If you’re a beginner and want to obtain attribute value, you can do so with ease. We might occasionally also need to obtain custom attribute values, namely data attribute values. I’ll show you three ways to retrieve a custom attribute’s value in jQuery in the example that follows.

Example:

<html lang="en">
<head>
	<title>Get Custom Attribute Value</title>
	<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.3/jquery.min.js"></script>
</head>
<body>
	<a href="example.com" data-id="1" myclass="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_myclass = $("a").attr("myclass");
	    alert(a_myclass);
	    

    </script>
</body>
</html>

Related Posts

Knee Replacement Surgery Guide: Symptoms, Surgical Options, and Physical Therapy

Introduction Persistent joint discomfort can disrupt everyday routines, making basic movements like climbing stairs, walking, or rising from a chair feel challenging. Finding effective knee treatment begins…

Read More

Complete Guide to Events in Kolkata: How to Discover What to Do

Finding something worthwhile to do across Kolkata often comes down to filtering noise rather than finding options. Between historic theatre corridors, contemporary auditorium programs, lively music venues,…

Read More

Enterprise Delivery Pipelines: Technical Strategies for DevOps Training China

Introduction Software development teams frequently experience severe delivery bottlenecks when handoffs between developers and operations engineers rely on manual interventions. Code that runs reliably on a developer’s…

Read More

Inside the Overseas Work Visa for Indians: A Relocation Advisor’s Strategic Playbook

Indian professionals looking to build an international career quickly discover that finding an overseas job is only half the battle. Securing the legal right to work in…

Read More

The Vital Role of Digital Inclusion Programs in Advancing Modern Social Welfare

Introduction When local governments and public institutions digitize vital civic resources—from municipal court filings and welfare applications to public housing portals—they often assume the broader public can…

Read More

Best Weekend Events in Delhi: How to Find and Plan Outings

Introduction Being a student or an early-career creator in the capital means having endless curiosity but operating within realistic financial boundaries. You want to immerse yourself in…

Read More
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x