Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to scroll to the particular div using jquery or javascript

I want to scroll to the particular div using jquery

I have written the code like:

 $("#button").on('click',function(){
     var p = $("#dynamictabstrp");
     var offset = p.offset();
     window.scrollBy(offset.left, offset.top);
 });

But it is not moving to the div position. How can i do that in jquery or javascript

like image 596
Jonathan Avatar asked Nov 09 '13 10:11

Jonathan


People also ask

How do I scroll down to a specific div?

The scrollTo method: The scrollTo() is used to scroll to the specified element in the browser.

How do I scroll down to a specific element in JavaScript?

Use the scroll() Function to Scroll to an Element in JavaScript. The element interface's scroll() function scrolls to a specific set of coordinates within a given element. This is suitable for Chrome and Firefox and not for the rest. Copy window.

How do I scroll to a specific position in HTML?

The scrollTo() method scrolls the document to specified coordinates.


1 Answers

Try

.scrollTop()

$(window).scrollTop($('#dynamictabstrp').offset().top);


or

scrollIntoView()

$('#dynamictabstrp')[0].scrollIntoView(true);

or

document.getElementById('dynamictabstrp').scrollIntoView(true);
like image 92
Tushar Gupta - curioustushar Avatar answered Nov 15 '22 20:11

Tushar Gupta - curioustushar