hasAttribute()
Introduction to the JavaScript hasAttribute() method
hasAttribute() methodlet result = element.hasAttribute(name);
Code language: JavaScript (javascript)Parameters
Return value
JavaScript hasAttribute() example
hasAttribute() example<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS hasAttribute() Demo</title>
</head>
<body>
<button id="btnSend" disabled>Send</button>
<script>
let btn = document.querySelector('#btnSend');
if (btn) {
let disabled = btn.hasAttribute('disabled');
console.log(disabled);
}
</script>
</body>
</html>
Code language: HTML, XML (xml)Summary
Last updated