1

index.php

<html>
    <head>
        <script type="text/javascript" src="jquerys/jquery.js"></script>
        <style>
            #parentcontainer div
            {
             height:900px;
             width:600px;
             clear:both;
             border:1px solid red; 
             padding:10px;
             margin:50px 0px; 
            }
        </style>
        <script>
        function showHint() 
            { 
                $('div').load('getdivs.php');  
                $(window).scroll(function()
                {
                    $( ':visible' ).filter('.same').each(function()
                    {
                        alert($(this).attr('id'));
                    });
                });
            }
        </script>
    </head>
    <body onload="showHint()">
        <p>Suggestions: <div class="same2" id="parentcontainer"></div></p>
    </body>
</html>

getdivs.php

<div class="same" id="childcontainer1">  content here 
</div>
<div class="same" id="childcontainer2"> content here 
</div>

When I scroll down the window, I am getting the alerts of all the div's with (.same) class irrespective of the div I am viewing on the window. I want the ID's respective to the DIV'S shown on page on scrolling.

someOne
  • 1,975
  • 2
  • 14
  • 20
santosh .d
  • 51
  • 8
  • And god has created [Google](http://stackoverflow.com/questions/19498068/how-to-get-on-screen-visible-element-objects-in-jquery). – someOne Mar 27 '15 at 06:27
  • 1
    @someOne Actually Google was created by Larry Page and Sergey Brin :) – Joakim M Mar 27 '15 at 07:50
  • I think this is an already answered question. This might help: https://stackoverflow.com/questions/15496136/getting-the-id-of-the-div-at-current-position – AlexAMG Jul 03 '17 at 18:26

0 Answers0