jQuery Element Selector (“element”)

Beginner
⏱️ 8 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Tag name

What You’ll Learn

The element selector matches every node with a given HTML tag namediv, 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

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().

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.

📝 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" );

⚡ Quick Reference

SelectorMatches
$("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)

📋 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

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
Try It Yourself

How It Works

jQuery collects every element whose tagName is DIV, then applies CSS through chaining.

Example 2 — Count Paragraphs: $("p").length

Display how many paragraph elements exist on the page.

jQuery
var count = $( "p" ).length;

$( "#paraCount" ).text( count + " paragraph(s)" );
Try It Yourself

How It Works

Element selectors often return multiple nodes. .length gives a count without looping.

📈 Practical Patterns

Scoping, combining selectors, and common tag targets.

Example 3 — Scoped Paragraphs: $("#article p")

Style paragraphs only inside one article — not every p on the page.

jQuery
$( "#article p" ).css( "line-height", "1.8" );



// Descendant combinator + element selector
Try It Yourself

How It Works

Pair element selectors with IDs or classes to avoid document-wide tag scans.

Example 4 — Element + Class: $("div.card")

Match only div elements that also have the card class.

jQuery
$( "div.card" ).addClass( "highlight" );



// span.card would NOT match — wrong tag
Try It Yourself

How It Works

Stacking type + class is a common pattern — narrower than .card alone when tag type matters.

🚀 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.

📝 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.

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 Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All modern versions
Full support
element Universal

Bottom line: Use lowercase tags. Scope $("p") with #id when the page has many paragraphs.

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.

💡 Best Practices

✅ Do

  • Use lowercase tag names in selectors
  • Scope: #article p instead of bare p
  • Combine type + class: button.primary
  • Use .length to count tag matches
  • Prefer specific tags over * when possible

❌ Don’t

  • Run $("div") on huge documents without scoping
  • Confuse $("div") with $(".div") (class)
  • Assume input excludes checkboxes or radios
  • Use uppercase tag names in selector strings
  • Rely on tag-only selectors when a class or ID is available

Key Takeaways

Knowledge Unlocked

Five things to remember about the element selector

Match by HTML tag name — div, p, input, …

5
Core concepts
div 02

Official

$("div")

Demo
get 03

Native

getElementsByTagName

Perf
.x 04

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.

Continue to ID Selector

After tag names, learn how to target a single unique element with #id syntax.

ID selector tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful