views:

214

answers:

2

I need a bit of Javascript that will find some text in the html page and then scroll to that point.

So something like "Are you a Lib Dem or Tory supporter and how do you feel about the deal?" would scroll down to the bottom of the page for this bbc news page: http://news.bbc.co.uk/1/hi/uk_politics/election_2010/8676607.stm

Im hoping there is a built in function for both the find text and scroll.

+2  A: 

Try this. It works on the site you provided:

$(window).scrollTop($("*:contains('Are you a Lib Dem or Tory'):last").offset().top);

It finds last, deepest element that contains given phrase on the page and scrolls to it.

Kamil Szot
Good man! That worked very well, would it be possible to add some animation to that so it scrolled down really fast? I have Jquery and ui installed. Thanks so much!
bluedaniel
In regards of animating scrolling take a look at this: http://www.learningjquery.com/2007/09/animated-scrolling-with-jquery-12
Kamil Szot
A: 

Um, not working for me. I have jquery and ui installed, I call this within a onload function, but get the error Warning: Unknown pseudo-class or pseudo-element 'contains'. What am I missing?

Peter