DBurton
DBurton

Reputation: 155

Find first div after THIS keyword

I have the following HTML:

<ul id="sort3" class="droptrue connectedSortable  ui-sortable" data-update-url="http://localhost:5000/workorders/sort " data-wostatus-id="236">
   <li class="workorder" id="workorder_37" style="">
      <div class=" 3" data-maxsynch="E">

The following picks up the data wostatus_id:

$(this).data('wostatus-id')

But, I haven't figured out how to get the data maxsynch. I tried this:

$(this).find("div:first").data('maxsynch')

It gets a maxsynch value, but not from the first div.

Upvotes: 0

Views: 81

Answers (3)

Arun P Johny
Arun P Johny

Reputation: 388326

Try

$(this).find("div[data-maxsynch]").data('maxsynch')

Demo: Fiddle

Upvotes: 0

Wojciech Budniak
Wojciech Budniak

Reputation: 102

You probably want :first-of-type instead of :first

Upvotes: 0

War10ck
War10ck

Reputation: 12508

You could try one of the following:

1) $(this).find('div[data-maxsynch]').first().data('data-maxsynch');

2) $(this).find('div[data-maxsynch]').first().attr('data-maxsynch');

This locates the first nested div that contains the data-maxsynch data attribute and pulls its value.

Upvotes: 1

Related Questions