HTML store data in data tag

If you want to store some data in a tage you could use the data- tag. try it:

1


code:
<!DOCTYPE html>
<html>
<body>

<p id="test" data-old="1">1</p>

<button onclick="myFunction()">Try it</button>

<script>
function myFunction() {
    document.getElementById("test").setAttribute("data-old",document.getElementById("test").innerHTML); 
    document.getElementById("test").innerHTML = 2*document.getElementById("test").innerHTML;
   
}
</script>

</body>
</html>
 

Leave a Reply

Your email address will not be published.

19 − sixteen =