jQuery Universal selector
Description and Syntax
$('*')
selects all elements.
Examples
$('*')
all elements in the document$('p > *')
all elements that are children of a paragraph element
<!DOCTYPE html>
<html>
<head>
<script src="http://java2s.com/style/jquery-1.8.0.min.js">
</script>
<script>
<!-- w w w.j a v a 2s.com-->
$(document).ready(function(){
var allElements = $("*");
document.writeln(allElements.length);
});
</script>
<body>
<div id="main">
<ul id="myList">
<li>A</li>
<li>B</li>
</ul>
</div>
</body>
</html>
Select all elements under a certain element
The following code selects all elements under a certain id.
<html>
<head>
<script src="http://java2s.com/style/jquery-1.8.0.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){<!--from w w w . j av a2 s. com-->
$("#main > *").css("border", "3px solid red");
});
</script>
</head>
<body>
<body>
<span id="main">
<div>asdf</div>
<button>Child</button>
<span>A Span</span>
</span>
</body>
</html>
Match all elements
The following code selects every element (including head
, body
, etc).
<html>
<head>
<script src="http://java2s.com/style/jquery-1.8.0.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){<!-- w w w . j av a 2 s. c om-->
$("*").css("border","3px solid red");
});
</script>
</head>
<body>
<body>
<div>A div</div>
<button>0</button>
<button>1</button>
<button>2</button>
<button>3</button>
<span></span>
</body>
</html>