I have this simple HTML:
<body>
<a>
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
</a>
</body>
The divs are children of <a>
.
From jQuery:
:last-child Selector
— Selects all elements that are the last child of their parent.
However, when running this code in JSBin:
$("div:last-child" ).css('background-color','red')
It yields this rendered output:
Even if we remove <a>
so that divs
will be direct children of <body>
:
<body>
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
</body>
The result is that nothing is painted: (http://jsbin.com/kamepu/4)
Those divs
are children of <body>
, so why isn't it working?
`.
– pavel Nov 23 '14 at 12:45