How do I work with data attributes in jQuery

jQuery, Data Attributes, HTML5, DOM Manipulation
This example demonstrates how to use data attributes with jQuery for dynamic content manipulation.
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <script> $(document).ready(function() { // Set data attribute $('#example').data('exampleKey', 'exampleValue'); // Retrieve data attribute var exampleValue = $('#example').data('exampleKey'); console.log(exampleValue); // Output: exampleValue // Update data attribute $('#example').data('exampleKey', 'newValue'); console.log($('#example').data('exampleKey')); // Output: newValue }); </script> <div id="example">Example Div</div>

jQuery Data Attributes HTML5 DOM Manipulation