getAttribute()
Introduction to the JavaScript getAttribute() method
getAttribute() methodlet value = element.getAttribute(name);
Code language: JavaScript (javascript)Parameters
Return value
JavaScript getAttribute() example
getAttribute() example<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS getAttribute() Demo</title>
</head>
<body>
<a href="https://www.javascripttutorial.net"
target="_blank"
id="js">JavaScript Tutorial
</a>
<script>
let link = document.querySelector('#js');
if (link) {
let target = link.getAttribute('target');
console.log(target);
}
</script>
</body>
</html>
Code language: HTML, XML (xml)Summary
Last updated