Learning JQuery – Selectors

I’ve only just begun to have exposure to JQuery/Javascript as a primary language. I’ve been progressively going through tutorials and other sites such as I’ve only just begun to have exposure to JQuery/Javascript as a primary language. I’ve been progressively going through tutorials and other sites such as and w3schools.

From what I’ve found, JS quite enjoyable and JQuery even more so as it reduces the code I need to write to get things done (at the expense of the initial learning).

I’ve got a long way to go but here is a minimalistic list I’ve made for myself of various Selectors and filtering on those selectors.

Selectors

[code language=”javascript”]

$allListItems = $(“li”);

$alldivs = $(“div”);

$whodom = $(“*”);

$byclass = $(“.someclass”);

$byId = $(“#Id”);

[/code]

Descendant Selector

[code language=”javascript”]

$all_li_in_fancylist = $(“li” .fancylist”);

[/code]

– Descendant of class/id etc constraint

= All items that are a descendants of list items that have a class of fancylist

Child Selector

[code language=”javascript”]

$(“.shiny > a”)

[/code]

-Ancestor > child type

= All links that are a child of an element with a class of shiny

Pseudo-Classes

[code language=”javascript”]

$(“li:first-child”)

[/code]

= Will select all list-elements that are the first child of their parent.

Filtering Selections

[code language=”javascript”]

$alldivs = $(“div”);

$lastdiv = $alldivs.last();

$2nddiv = $alldivs.eq(1);

[/code]