Skip to content

Instantly share code, notes, and snippets.

@Jo0001
Created January 3, 2020 12:18
Show Gist options
  • Save Jo0001/ded40a515945cad5fa3c61fc81908b57 to your computer and use it in GitHub Desktop.
Save Jo0001/ded40a515945cad5fa3c61fc81908b57 to your computer and use it in GitHub Desktop.
Get the value of a data- attribute
<!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