scroll function for multiple id's

jquery multiple ids same function
multiple id selector jquery
get div id on scroll jquery
how to get multiple id value in jquery
jquery multiple id selectors on click
scroll end event javascript
jquery trigger event when scroll to div
jquery appear on scroll

I have the following code to have a div stick to the top upon scroll:

$(window).scroll(function() {
//After scrolling 100px from the top...
if ( $(window).scrollTop() >= 72 || (w > 980)) {
    $('#div1').css('top', '0px');

//Otherwise remove inline styles and thereby revert to original stying
} else {
    $('#div1').attr('style', '');


Now I want two divs on one page to have the same behaviour. I tried:

 $('#div1' || '#div2')

but that does not seem to work. How could I achieve this?

Either comma separate them like $('#div1, #div2') or just add a class instead of using id's like $('.stickyDiv') and then

<div class="stickyDiv" id="div1></div>
<div class="stickyDiv" id="div2></div>

How to use the same jQuery scrolling function for multiple elements , Maybe you can use a function like this I made reusing some parts of your code: function scroll(id,show,limit,timeout){ $(window).scroll(function(){ if ($(this). If you want to set the scroll multiple times you need to offset by your current scroll location. Here's how I did it in jQuery: $('#scrolling_div').scrollTop($('#scrolling_div').scrollTop() + $('#element_within_div').position().top); – Will Aug 14 '14 at 17:43

If your aim is to stick the div on top while scrolling, I suggest you to use a CSS attribute called position.

Example: Codepen

You can read more about it here.

Multiple uses of $window.scroll, Scroll(function() is, maybe that is how you distinguish between which version of the <body id="top" style="height: 8000px;"> <nav class="site-header">Site� The scroll event occurs when the user scrolls in the specified element. The scroll event works for all scrollable elements and the window object (browser window). The scroll() method triggers the scroll event, or attaches a function to run when a scroll event occurs.

This can be achieved with position:sticky.

#div1 , #div2 {
    position: sticky;
    top: 72px;

By default, they will behave as position: relative. When the Parent Element is scrolled (passed the 72px point), they will behave like position: fixed.

This will happen only within the scrolling of the Parent Element. If you want them to be sticky relative to the window, place them as direct children of the <body>.

    <div id="div1"></div>
    <div id="div2"></div>

JQuery, How to scroll the page up or down using anchor element in jQuery ? Select the ID's of different element and then use each() method to Display the text which indicates the multiple ID selectors. function GFG_Fun() {. Conclusion. This tutorial covered how to use the Search and Scroll API feature for Python to scroll queries for all documents in an Elasticsearch index using the Python low-level client library and how to use the Scroll API function to get all of an index’s documents in multiple batches.

How to detect when user scrolls to the bottom of a div, In the case of multiple event values, those are separated by space. Example 1: This example alerts You reached the end of the DIV when the user scrolls to the bottom of the div body style = "text-align:center;" id = "body" >. While the _scroll_id may change between requests, it doesn’t always change — in any case, only the most recently received _scroll_id should be used. If the request specifies aggregations, only the initial search response will contain the aggregations results.

jQuery scroll() Method, The scroll event works for all scrollable elements and the window object (browser window). The scroll() method triggers the scroll event, or attaches a function to� // Using jQuery's animate() method to add smooth page scroll // The optional number (800) specifies the number of milliseconds it takes to scroll to the specified area $('html, body').animate({ scrollTop: $(hash).offset().top }, 800, function(){ // Add hash (#) to URL when done scrolling (default click behavior) window.location.hash = hash;

Calling JavaScript code on multiple DIV elements without ID attribute, Calling JavaScript code on multiple DIV elements without ID attribute Same thing here, only using a different JavaScript function. only reduce the size of your code but also scroll through all existing elements in a collection� The Scroll Lock key on a laptop is often a secondary function of another key, located near the Backspace key. If a laptop is using two keys as one key, you must press the Fn key with the second key you want to use. On a laptop, the ScrLk, Pause, and Break functions are usually part of another key and are in blue text.

  • I will try this also, I am only not sure it works in all browsers?