CSS last-child(-1)

I am looking for a css selector that lets me select the pre-last child of list. <ul> <li>1</li> <li>2</li> <li>3</li> <li>4</li> <li>5</li> <!– select the pre last item dynamically no matter how long this list is –> <li>6</li> </ul> Static method: ul li:nth-child(5) Dynamic method: ul li:last-child(-1) which of course doesn’t validate, also nth-last-child doesn’t … Read more

Using querySelectorAll to retrieve direct children

I am able to do this: <div id=”myDiv”> <div class=”foo”></div> </div> myDiv = getElementById(“myDiv”); myDiv.querySelectorAll(“#myDiv > .foo”); That is, I can successfully retrieve all the direct children of the myDiv element that have class .foo. The problem is, it bothers me that I must include the #myDiv in the selector, because I am running the … Read more