Articles → JavaScript → Document.Queryselector In Javascript
Document.Queryselector In Javascript
Purpose
Syntax
document.querySelector("selectors")
Example
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<div id="dvTest"> This is the test div </div>
</body>
</html>
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<div id="dvTest"> This is the test div </div>
<script>
alert(document.querySelector("#dvTest").innerText);
</script>
</body>
</html>
Output