Created
January 3, 2020 12:18
-
-
Save Jo0001/ded40a515945cad5fa3c61fc81908b57 to your computer and use it in GitHub Desktop.
Get the value of a data- attribute
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Test</title> | |
</head> | |
<body> | |
<button onclick="showValue()">showValues in console</button> | |
<p data-test="Max Mustermann">Test1</p> | |
<p data-test="Paul Mustermann">Test2</p> | |
<script> | |
function showValue() { | |
let content = document.querySelectorAll('[data-test'); | |
let arrayLength = content.length; | |
for (let i = 0; i < arrayLength; i++) { | |
let value = content[i].getAttribute("data-test"); | |
console.info(value); | |
} | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment