ItSolutionStuff.com

How to Get Attribute Value in JQuery?

By Hardik Savani • April 6, 2023
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.

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>

I hope it can help you...

Tags: jQuery
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

How to Remove Special Characters from a String in JQuery?

Read Now →

JQuery Remove All Numbers from String Example

Read Now →

How to Download File using JQuery?

Read Now →

How to use Laravel Variable in JQuery?

Read Now →

Jquery Convert Object to String Example

Read Now →

JQuery - How to Count Child Elements in Div?

Read Now →

JQuery Remove Parent Table Row on Button Click Event

Read Now →

How to Check If Key Exists in JSON Object using JQuery?

Read Now →

How to Remove Comma from String in JQuery?

Read Now →

JQuery Draggable Sortable Table Rows Example

Read Now →

How to Upload Image using jQuery Ajax in PHP?

Read Now →

How to Allow Only One Checkbox Checked at a Time in JQuery?

Read Now →

How to Check Undefined, Empty and Null in JQuery?

Read Now →

How to Convert Line Breaks to br in jQuery ?

Read Now →