` elements.
> β οΈ **Performance Warning:** The universal selector `*` can be extremely slow and resource-intensive in older browsers because it has to traverse and select every single node in the DOM tree. Use it sparingly and with caution in production environments.
---
## Syntax
```javascript
$("*")
```
---
## Code Examples
### Example 1: Selecting All Elements in the Document
The following example demonstrates how to select every element on the page and apply a CSS border to them.
```html
This is a heading
This is a paragraph.
This is another paragraph.
``` ### Example 2: Selecting All Elements Inside a Specific Container You can restrict the scope of the universal selector by combining it with a parent selector. This is much better for performance. ```htmlHeading inside container
Paragraph inside container.
This paragraph is outside the container and will not be affected.
``` --- ## Best Practices and Considerations 1. **Performance Overhead:** Because `$("*")` matches every element on the page, jQuery must loop through the entire DOM tree. If you only need to style elements, prefer using global CSS rules (e.g., `* { box-sizing: border-box; }`) instead of jQuery, as browser CSS engines are highly optimized for this. 2. **Context is Key:** Always try to qualify the universal selector by nesting it under a specific ID or class (e.g., `$("#my-id *")`) to limit the scope of the DOM traversal. 3. **Implicit Universal Selector:** In many jQuery methods, omitting the selector or using certain combinators implicitly acts like a universal selector. Understanding how selectors chain can help you write cleaner, faster code.
YouTip