Jquery Set custom data attribute value | Jquery Get custom data attribute value

Jquery Set custom data attribute value | Jquery Get custom data attribute value

In this post we will give you information about Jquery Set custom data attribute value | Jquery Get custom data attribute value. Hear we will give you detail about Jquery Set custom data attribute value | Jquery Get custom data attribute valueAnd how to use it also give you demo for it if it is necessary.

In this example, we will learn how to get custom attribute value in jquery and how to set custom attribute value in jquery. we will use attr() and data() for getting custom attribute value and set custom attribute value in js.

We can easily set data attribute value in jquery, also you can do it same thing with custom attribute value in jquery.

We almost require to set and get custom attribute when you are working with jquery code on your php or laravel project. when ever you need to set and get custom attribute value then this examples will help you.

I gave you bellow two example, so you can use any one as you want.

Example 1

<!DOCTYPE html>

<html>

<head>

<title>Jquery Set custom data attribute value | Jquery Get custom data attribute value - ItSolutionStuff.com</title>

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>

</head>

<body>

<div id="example1">Working with me</div>

<button >Set Attribute</button>

<button >Get Attribute</button>

<script type="text/javascript">

$(".set-attr").click(function(){

$("#example1").attr('custom-name', 'ItSolutionStuff.com');

});

$(".get-attr").click(function(){

var name = $("#example1").attr('custom-name');

alert(name);

});

</script>

</body>

</html>

Example 2

Also see:How to get selected radio button value in Jquery?

<!DOCTYPE html>

<html>

<head>

<title>Jquery Set custom data attribute value | Jquery Get custom data attribute value - ItSolutionStuff.com</title>

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>

</head>

<body>

<div id="example2">Working with me</div>

<button >Set Attribute</button>

<button >Get Attribute</button>

<script type="text/javascript">

$(".set-data").click(function(){

$("#example2").data('name', 'ItSolutionStuff.com 2');

});

$(".get-data").click(function(){

var name = $("#example2").data('name');

alert(name);

});

</script>

</body>

</html>

I hope it can help you…

Hope this code and post will helped you for implement Jquery Set custom data attribute value | Jquery Get custom data attribute value. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

Leave a Comment

Your email address will not be published. Required fields are marked *

7  +  3  =  

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US