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


Picture showing the output of document.queryselector in JavaScript



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

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250