Tag Archives: jQuery basic selectors

01 – Basic selectors in jQuery

jQuery is all about manipulating HTML elements. In order to manipulate the HTML elements you have to select them. You can select them in different ways.

The All (Universal) selector

The All selector allows you to select all the elements of the page (all DOM elements of a page). It is represented by an asterisk, *.
Let’s consider a simple HTML page with different elements in it.

<!DOCTYPE html>
<html>
<head>
	<title>My site</title>
	<script src="jquery-3.2.1.min.js"></script>
</head>
<body>

<div class="main-div">
	<h3>I am a header</h3>
	<p>I'm a paragraph</p>
	<img id='my-img' src='dan.jpg' alt="Dan pic">
</div>

<script>
	var $allElements = $('*');
</script>

</body>
</html>

Continue reading