jquery get data attribute

Jquery Get custom data attribute value & jquery find element by data attribute

index.html

<!DOCTYPE html>
<html>
<head>
    <title>Jquery Set custom data attribute value | Jquery Get custom data attribute value - Pakainfo.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 class="set-data">Set Attribute</button>
<button class="get-data">Get Attribute</button>
      
<script type="text/javascript">
  
$(".set-data").click(function(){
    $("#example2").data('name', 'Pakainfo.com 2');
});
   
$(".get-data").click(function(){
    var name = $("#example2").data('name');
    alert(name);
});
  
</script>
   
</body>
</html>