Add or set value in data-attribute using JQuery

Add or set value in data-attribute JQuery

<html>
	<head>
		<title>Codelizar JQuery Data Attribute</title>
		<script src='https://code.jquery.com/jquery-3.4.1.js'></script>
	</head>
	<body>
		<div id="mybox" data-boxval="98"></div>
                <div id="newbox" data-mygroup=""></div>
	</body>

        <script type='text/javascript'>
           var new_value = $('#mybox').data('boxval'); //get the value from div
           $('#newbox').data('mygroup',new_value); //set the value
        </script>
        
</html>


Leave a Reply

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