Skip to main content

jQuery has the $() function that actually selects a web page's parts. Any CSS selector expression or DOM node can be passed as argument; its results are all found elements.

- Advertisement -
- Advertisement -

So we can easily use them for manipulation in order to modify their behavior.

For example:

$('div') will access all div elements

$('#X') will access all elements with id X

$('.x') will access all elements which class is x

$('p') will access all paragraphs in a web page

Let's say that we want to add a class 'newclass' to all paragraph elements. We need to add the following lines after jQuery library is loaded:

<script src="jquery-1.7.2.js" type="text/javascript"></script>
  $(document).ready(function() {

- Advertisement -