Computer Magic Logo
Selector features

Thursday, January 12, 2017

Published by Aristotelis Pitaridis

There are some special ways to select elements using jQuery. Below we can see some examples.

var elements1 = $('div:contains("computer")');      // Select all div elements which contains the text "computer". It is case sensitive.
var elements2 = $('tr:odd');                        // Select all the odd tr (1, 3, 5, etc). Index is 0 based. The first row in table is 0;
var elements3 = $('tr:even');                       // Select all the even tr (0, 2, 6, etc). Index is 0 based. The first row in table is 0;
var element4 = $('span:first-child');               // Select the first span child of every element group.
var element5 = $('span:last-child');                // Select the last span child of every element group.