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



Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Wednesday, April 05, 2017

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250