0

I have the following markup and want to place 'here is my info' after this when an ajax callback is triggered. My markup:

<div data-item-header-id="17">
here is an item
</div>
<div data-item-header-id="17">
here is another item
</div>
<!-- put 'here is my info here' here -->
<div data-item-header-id="18">
here is another item
</div>

The alert is called but isn't being put in the right place. How would I select given the above markup?

if(r.is_placed_at_end=='true'){
  alert('will place at end');
  $('data(item-header-id==17):last)').after("here is my info");
}

I tried looking at this but didn't get me all the way there. jquery data selector

Also, is this proper usage of data elements?

thx

Community
  • 1
  • 1
timpone
  • 19,235
  • 36
  • 121
  • 211

1 Answers1

1

You want to use an attribute selector.

$('div[data-item-header-id="17"]:last').after("here is my info");

Demo: http://jsfiddle.net/CcA3D/

Reference: http://api.jquery.com/category/selectors/

charlietfl
  • 170,828
  • 13
  • 121
  • 150