The HTML document.querySelector() method

The querySelector() method returns the first element that matches a specified CSS selector (such as ID, class name, or type) in a document. If multiple elements have the same selector, then only the first one is returned.

Consider the following code snippet,​ which demonstrates the usage of the querySelector() method:

  • HTML
New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved