1

In an MVC 5 Razor view, in a div, a collection of items is displayed, where each item is in it's own span. You could do this with a DisplayTemplate:

<div class="ItemListContainer fa-2x">
   @Html.DisplayFor(model => model.ItemList)
</div>

And the display template could be as simple as:

<span class="@ListItemClass">@Model.item</span>

0 items:

<div></div>

1 item:

<div><span>item1</span><div>

More than a few items:

<div><span>item1</span><span>item2</span><span>item3</span><span>item4</span><span>item5</span><span>item6</span><div>

As you display more items from the collection, and depending on output widths (21 inch monitor v.s 3 inch hand-held device), there is a possibility that the next displayed span will be wrapped to the next line.

Accounting for all the above, is there a way to know the view x & y position of any displayed span with jQuery? I can add Id's to each span to keep track of them for reference later.

Idealy, I would like the DisplayTemplate to know the position of the last span it just 'displayed', to be used in the current iteration it's trying to display.

If this is a duplicate (I couldn't find it) please add the link!

If I need to clarify something, let me know.

Robert Achmann
  • 1,986
  • 3
  • 40
  • 66
  • Possible duplicate of [Get the position of a div/span tag](http://stackoverflow.com/questions/288699/get-the-position-of-a-div-span-tag) – bshivram Dec 20 '16 at 06:22

0 Answers0