Yetimwork Beyene
Yetimwork Beyene

Reputation: 2337

How to get the element of data attribute value using jquery?

Consider the following, how do get the last element of a particular data attribute value?

      <tr data-log="sectionA"><td>Log Information</td></tr>
      <tr data-log="sectionA"><td>Log Information</td></tr>
      <tr data-log="sectionA"><td>Log Information</td></tr>
      <tr data-log="sectionA"><td>Log Information</td></tr> <--- I need this last element of sectionA
      <tr data-log="sectionB"><td>Log Information</td></tr>
      <tr data-log="sectionB"><td>Log Information</td></tr>
      <tr data-log="sectionB"><td>Log Information</td></tr>
      <tr data-log="sectionB"><td>Log Information</td></tr>

I'm not sure what to try.. thanks for any ideas...

Upvotes: 3

Views: 868

Answers (1)

Musa
Musa

Reputation: 97672

How about

$('[data-log="sectionA"]:last')

http://jsfiddle.net/U9HQH/

Upvotes: 3

Related Questions