jQuery - Selector Examples

You can select an element with jQuery by using one of three selectors: by tag ID (#), by tag TYPE (DOM element), and by CSS Class.

Row 1 Cell 1 Row 1 Cell 2
Row 2 Cell 1 Row 2 Cell 2
Row 3 Cell 1 Row 3 Cell 2
Row 4 Cell 1 Row 4 Cell 2
Row 5 Cell 1 Row 5 Cell 2

Second Header

 


//Enable / Disable these to experiment.
$('td:contains("Row 3")').css('background-color', 'green');                 //using Contains
$(':header:has("span")').css('color', 'red').css('font-weight','bold');     //using Has
$('[type]').css('color','blue');                                            //Using [attribute]
$('[type=text]').css('color', 'purple');                                    //Using [attribute]=[value]
$(':button, :text').css('font-size', '18px');                               //Matching specific elements
$(':checkbox').attr('checked', true);                                       //Can set attributes...