JQuery – Select First, Last, Nth, Second Children

Ever wondering how to select children in JQuery? No? Then skip to the next article.

My case is the following – I present a div with divs, and I try to select its children, changing the borders and the background. Simple as this:


Thus, first I have given ids as main1, main2 and main 3 to my main divs. Then I have tried to select their children with some properties from within the brackets as “div:last-child” and outside the brackets as last(). Even the works pretty well, adding text “This is the second child”.

Long story short – here comes the code:

Here is the code in GitHub.

Enjoy it! 😀

Tagged with: , , ,