0

Got this list of images. I would like to display the value of data-id of the figure which is closest to the 200px from the top of the browser. See when I scroll down i see the values 740 then 756 then 788 etc.

  <div id="counter" style="position:fixed;top:10px;left:10px;height:200px;width:200px;"></div>


 <figure style="height:200px;" data-id="740"></figure>
    <figure style="height:200px;" data-id="756"></figure>
    <figure style="height:200px;" data-id="788"></figure>
    <figure style="height:200px;" data-id="920"></figure>
Mark Henry
  • 2,649
  • 7
  • 40
  • 48

1 Answers1

0

You can use .first() or :first to select the first element from a given selector on the page.

e.g.

$("figure").first()

$("figure:first")

Then to get the data-id attribute you can add:

$("figure:first").data("id")

jonbaldie
  • 378
  • 5
  • 12