The element selector matches every node with a given HTML tag name — div, p, input, and so on. Available since jQuery 1.0; one of the first selectors beginners learn alongside class and ID.
01
Syntax
$("div")
02
tagName
DOM type
03
Official
div demo
04
Combine
div.card
05
Scope
#main p
06
Native
getElementsByTagName
Fundamentals
Introduction
Before classes and IDs, HTML documents are built from tags — <div>, <p>, <a>, <input>. The element selector targets nodes by that tag name: pass the tag as a string to $() with no prefix.
Official jQuery documentation notes that the parameter refers to the tagName of DOM nodes. When you write $("div"), jQuery calls the browser’s getElementsByTagName() and returns a jQuery collection you can chain with methods like .css() or .hide().
Concept
Understanding the Element Selector
An element selector is a type selector in CSS terms:
$("div") → every <div> in the context — nested or not.
$("span") → every <span>; does not match <div>.
$("input") → all input types unless you add [type=...].
Combine: $("li.active") → li elements with class active.
💡
Beginner Tip
Bare tag selectors on large pages can return many nodes. Scope with an ID or class first: $("#article p") instead of $("p") when you only mean paragraphs inside one article.
Foundation
📝 Syntax
Official jQuery API form (since 1.0):
jQuery
jQuery( "element" )
// common patterns:
$( "div" )
$( "p" )
$( "input" )
$( "div.card" ) // element + class
$( "#sidebar li" ) // scoped descendant
Parameters
element — the HTML tag name to search for (typically lowercase).
Return value
A jQuery object containing every element with that tag name in the search context.
Empty collection when no matching tags exist.
Official jQuery API example
jQuery
// Finds every DIV element and adds a red border
$( "div" ).css( "border", "9px solid red" );
Cheat Sheet
⚡ Quick Reference
Selector
Matches
$("div")
All div elements
$("p")
All paragraph elements
$("div.card")
div elements with class card
$("#list li")
li elements inside #list
$("input[type=text]")
text inputs only (element + attribute)
Compare
📋 Element vs Class, ID, and Universal
Type selector and how it combines with other basics.
Element
div
By tag name
Class
.card
By class token
ID
#header
One unique node
Universal
*
Every tag type
Hands-On
Examples Gallery
Example 1 follows the official jQuery div demo. Examples 2–5 cover counting tags, scoped paragraphs, element + class, and styling all links. Use the Try-it links to run each snippet.
📚 Official jQuery Demo
Border every div — span and other tags are skipped.
Example 1 — Official Demo: $("div")
Official jQuery demo — add a thick red border to every div element.
jQuery
$( "div" ).css( "border", "9px solid red" );
// DIV1 and DIV2 match; SPAN does not
Single-tag selectors are simple but broad — consider scoping to nav a or #content a in production.
Applications
🚀 Common Use Cases
Layout blocks — $("div") or $("section") for structure passes.
Typography — $("#article p") for readable line height.
Forms — $("form input") to validate or style all inputs.
Lists — $("ul li") for menu or list item styling.
Media — $("img") for lazy-load or responsive classes.
Combined — $("button.primary") for typed component variants.
🧠 How jQuery Evaluates element
1
Parse tag name
jQuery reads the string as an HTML element type — e.g. div, p.
Syntax
2
Native lookup
Calls getElementsByTagName() for bare element selectors (official docs).
Fast path
3
Wrap nodes
Matching DOM nodes become a jQuery object for method chaining.
Collection
4
✓
Return collection
Chain .css(), .on(), .each(), and more.
Important
📝 Notes
Available since jQuery 1.0 — standard CSS type selector.
Parameter refers to tagName of DOM nodes (official API).
Uses getElementsByTagName() for element-only selectors.
Use lowercase tag names: div, not DIV, in selectors.
Combine with class, ID, and combinators for precise queries.
Scope broad tags — $("div") on large pages can match hundreds of nodes.
Compatibility
Browser Support
Element (type) selectors are core CSS and work in jQuery 1.0+. All modern browsers support document.querySelectorAll("div") and document.getElementsByTagName("div"). jQuery wraps native results consistently across browsers.
✓ CSS · jQuery 1.0+
jQuery Element Selector ("element")
Supported in all modern browsers. Native: getElementsByTagName("div"). Match by HTML tag name.
100%Standard CSS
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
elementUniversal
Bottom line: Use lowercase tags. Scope $("p") with #id when the page has many paragraphs.
Wrap Up
Conclusion
The element selector matches every node with a given HTML tag name — the foundation of CSS-style queries in jQuery. The official $("div") demo borders every div while leaving other tags untouched.
Combine with classes, IDs, and combinators for precision, and scope broad tag searches to a container when pages grow large. Next, learn the class selector for attribute-based grouping.
Rely on tag-only selectors when a class or ID is available
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about the element selector
Match by HTML tag name — div, p, input, …
5
Core concepts
tag01
element
By tagName
Syntax
div02
Official
$("div")
Demo
get03
Native
getElementsByTagName
Perf
.x04
Combine
div.card
Pattern
#05
Scope
#main p
Tip
❓ Frequently Asked Questions
The element selector matches every DOM node with a given HTML tag name. $("div") selects all div elements in the search context; $("p") selects all paragraphs. Available since jQuery 1.0 — the same as CSS type selectors.
Conceptually yes. Official jQuery docs state that getElementsByTagName() is called when you use a bare element selector. jQuery wraps the results in a jQuery object so you can chain .css(), .on(), and other methods.
In HTML documents, tag names are case-insensitive in the DOM, but jQuery and CSS conventions use lowercase: $("div"), $("span"), $("input"). Using lowercase avoids surprises in XML/XHTML or mixed documents.
Element selects by tag type — every matching tag on the page. Class (.card) and ID (#header) narrow by attributes. Combine them: $("div.card") means div elements that also have class card.
Yes. $("div") matches every div in the context — parent and nested. To limit depth, scope with an ID (#sidebar div) or use the child combinator (ul > li).
Yes. Type selectors are core CSS and work in jQuery 1.0+ and native querySelectorAll("div").
Did you know?
When jQuery sees a bare tag name like div, it delegates to getElementsByTagName — one of the oldest and fastest DOM lookup APIs. That is why $("div") is often faster than scanning with the universal $("*") selector.