Find a Text and scroll into it with javascript

I have a div that contains hundreds of lines. I want to create a function that allows me to find a text and scroll into it:

function findAndScroll(text)

So, I enter the wanted text in an input text, I click on the "Go" button that will trigger the "findAndScroll" function then I get scrolled to that text.

Before coding, is there an existant jQuery plugin or a javascript library that can do this?

Thank you,



You can use a function like this to find the text and highlight it. You can then scroll to the highlighted element like this:

var offset = $("#id_of_highlighted_element").offset().top;

or you can simply go the id like this

window.location = "#id_of_highlighted_element";

However window.scrollTo is more flexible because you can set the element to wherever you want on the page.

Need Your Help

SqlServer.Management.SMO.Server error when beginning transaction

c# sql-server transactions smo

Having an error when using SMO. This code has been working in VB.Net 4 and was just moved to C# and is now not functioning.

Find and verify path strings in text file using PowerShell, RegEx search

regex powershell

First time posting here, and I'll try to be clear and detailed, but be gentle if I missed an existing answer when I searched these boards.