CSS Portal
Run
Search
« Back to
HTML data Global Attribute
<!DOCTYPE html> <html> <head> <title>Data Global Attribute</title> </head> <body> <p id="test">Click on an item for details:</p> <script> function showDetails(test) { var testType = test.getAttribute("data-test"); alert(test.innerHTML + " is a " + testType + "."); } </script> <ul> <li onclick="showDetails(this)"data-test="star">The Sun</li> <li onclick="showDetails(this)"data-test="satellite">The Moon</li> <li onclick="showDetails(this)"data-test="planet">Mercury</li> </ul> </body> </html>
If this site has been useful, we’d love your support! Running this site takes time and resources, and every small contribution helps us keep creating valuable content. Consider buying us a coffee to keep things going strong!
☕ Buy a Coffee