1

I have this html code:

<p class="test" data-id=1>Some Value</p>

<p class="test" data-id=2>Some Value</p>

<p class="test" data-id=3>Some Value</p>

<p class="test" data-id=4>Some Value</p>

How can I select a <p> element based on its data-id?

H H H
  • 489
  • 1
  • 7
  • 20

1 Answers1

1

With jQuery:

alert($("p[data-id='1']").html());

DEMO

jQuery - Attribute Selector

  • Thanks mate. How can I select a particular element with its class name and data attribute? Im trying $('.test').data('id'=2); but its not working. – H H H Oct 06 '13 at 14:13