jquery Scroll to class name

jquery scroll to element
jquery scroll to element in div
jquery scroll to div
jquery scrolltop
jquery scroll to specific position
jquery scroll to top of div
jquery scrollintoview
start executing jquery function when i scroll to a specific <div>

I have the Html code like below,

<div data-stored="storenow" data-save="save" class="saveIcon" data-unique="game">Save</div>

And I write the jquery to scroll to the gameNo 456 like below.

var container = $("html,body");
var scrollTo = $(this).find('.saveIcon').attr('data-unique', 456);

    scrollTop: scrollTo.offset().top - container.offset().top + container.scrollTop()

I am using jQuery version 1.9. I am getting error in console:

Cannot read property 'top' of undefined

Is that not possible to scroll to class name instead of id?

But it is working fine in Firefox. But not in chrome or IE.

I try to find the solutions from stackoverflow. But all other solutions are different than my case.

You are not targeting a DOM object, you are targeting a string.

scrollTo = $(this).find('.saveIcon').attr('data-unique', 456); -> this is wrong

So, while you are trying to target an element, you are actually setting the 'data-unique' to the '.saveIcon' element.

Try this:

scrollTo = $('.saveIcon');

Working code:

var $container = $("html,body");
var $scrollTo = $('.saveIcon');

$container.animate({scrollTop: $scrollTo.offset().top - $container.offset().top + $container.scrollTop(), scrollLeft: 0},300); 

JQuery Scroll to .div, Minimize HTML Editor; Fold All; Unfold All. xxxxxxxxxx. 9. 1. <div class="top">. 2. <h1>Top</h1>. 3. </div>. 4. <div class="middle">. 5. <h1>Middle</h1>. 6. </div>. Teams. Q&A for Work. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information.

have you looked at scroll to view function?



.scroll(), scroll( handler )Returns: jQuery. Description: Bind an event handler to the "scroll" JavaScript event, or trigger that event on an element. Assuming all elements with problems have been given the class of error, we can scroll to the first one using jQuery’s.first () method before chaining on.offset () and the property top as before. $ ('html, body').animate ({ scrollTop: ($ ('.error').first ().offset ().top) },500); Now, go get scrolling!

these two codes worked for me like a charm this first will take to scroll to the top of the page but if you want to scroll to some specific div use the second one with your div id.

$('body, html, #containerDiv').scrollTop(0);

If you want to scroll to by a class name use the below code

enter code here
var $container = $("html,body");
var $scrollTo = $('.main-content');

$container.animate({scrollTop: $scrollTo.offset().top - $container.offset().top + 
$container.scrollTop(), scrollLeft: 0},300);

Find next div with a certain class and scroll to., Hi all, im trying to detect the next div with the class .content then scroll to it. Im now strugeling with $(".pagnering_number").click(function() { var. The second method is actually converted to the first method by jQuery behind the scenes. The first method is the endorsed way to do it. You're also correct regarding the div - adding that tells jQuery to only check divs for the classname, instead of all elements. – Mike Robinson Jun 14 '10 at 2:49

I am using following plain js, please try if you can use it in you codes:

$('a.smooth-scroll[href*=#]:not([href=#])').click(function () {
    if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) {
        var target = $(this.hash);
        target = target.length ? target : $('[name=' + this.hash.slice(1) + ']');
        if (target.length) {
                scrollTop: target.offset().top
            }, 1000);
            return false;

element.scrollIntoView, Scroll the element with id="content" into the visible area of the browser window: var elmnt = document.getElementById("content"); elmnt.scrollIntoView();. There is no .scrollTo() method in jQuery, but there is a .scrollTop() one..scrollTop expects a parameter, that is, the pixel value where the scrollbar should scroll to.

jQuery scroll() Method, The scroll event works for all scrollable elements and the window object (browser window). How to toggle between classes on different scroll positions. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. Learn more last element with a class name in a div

scroll-to-class-id-using-jquery-for-yui · GitHub, jQuery("[class*='" + prefix + "']").each(function() {. // More than one class? Find the matching one for each element. var classList = this.className.split(/\s+/);. By using an href attribute inside an anchor tag you can scroll the page to a specific element using a # in front of the elements id name. Also, here is some jQuery/JS that will accomplish putting variables into a div.

How to Smoothly Scroll to a Specific Element using jQuery, This tutorial relies on the jQuery JavaScript library in order to function; you must a href = "#target-element" class = "scroll_to" >Scroll to Target  A scroll event is sent whenever the element's scroll position changes, regardless of the cause. A mouse click or drag on the scroll bar, dragging inside the element, pressing the arrow keys, or using the mouse's scroll wheel could cause this event.

  • jQuery 9??? John Resig will be shocked ;)
  • I have so many data-unique values such as 456, 567, 789, etc., And it need to scrollto specific data-unique value. For sample, here 456. Please suggest me, If I am wrong.
  • you can try this type of selector: var $scrollTo = $('.saveIcon[data-unique="456"]');
  • This is only supported by Firefox so not a great solution, it's a shame because it's simple and works lovely on Firefox.
  • @alsobubbly Browser compatibility goes back to IE8 pretty sure it works just doesn't offer other options.
  • According to your link (developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView) most browsers only have basic support, only FireFox supports scrollIntoViewOptions. So yes it will work but it's experimental technology so the behaviour could change in future versions of browsers as the specification changes. Would be great to see this being widely supported though.