Scarface
Scarface

Reputation: 3913

:last-child is not being recognized

I have a scroll to function that I need to execute to scroll to the last message in its container, which is the container with chunk_id. The problem is that it works as is for going to the container, but if I add last-child into the mix the function does not work. Any ideas what I am doing wrong?

Works

$.scrollTo('div[chunk_id="'+autoscroll+'"]', 800, {easing:'elasout',offset:-250} );

Does not

$.scrollTo('div[chunk_id="'+autoscroll+'"]:last-child', 800, {easing:'elasout',offset:-250} );

Upvotes: 2

Views: 151

Answers (2)

SLaks
SLaks

Reputation: 887413

You're trying to find the :last-child inside of the div, using the child selector:

'div[chunk_id="'+autoscroll+'"] > :last-child'

Your code applies the :last-child filter to the div selector itself, so it only matches elements which are both div[chunk_id="'+autoscroll+'"] and :last-child.

Upvotes: 1

lonesomeday
lonesomeday

Reputation: 237855

I think you want to find the last child element of the div. Your code is currently selecting the last div with a particular chunk_id that is also the last child of its parent. This may well not exist.

You should use the child selector > combined with :last-child to find the last child element of the element already selected:

$.scrollTo('div[chunk_id="'+autoscroll+'"] > :last-child', 800, {easing:'elasout',offset:-250} );

Upvotes: 3

Related Questions