Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

change data attribute jquery

//sometimes it is better to use JS
<script>
// 'Getting' data-attributes using getAttribute
var plant = document.getElementById('strawberry-plant');
var fruitCount = plant.getAttribute('data-fruit'); // fruitCount = '12'

// 'Setting' data-attributes using setAttribute
plant.setAttribute('data-fruit','7'); // Pesky birds
</script>
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #change #data #attribute #jquery
ADD COMMENT
Topic
Name
5+4 =