0

I have this div:

<div data-value='example1' class='item'>example1</div>

I am trying to select this div by the data-value and am confused about how to do so? Note: I am using a plug-in that depends on both the given class and id so changing / adding classes and ids would not work as a solution. The only unique value of each div is the data-value, which I'm trying to target with the selector.

$("data-value='example1'").click(function(){
  alert('Hello')
})

I know above is wrong, but that's the idea I'm shooting for. Any ideas?

Keavon
  • 6,837
  • 9
  • 51
  • 79
user3007294
  • 931
  • 1
  • 14
  • 33
  • 1
    Have a look at how to use CSS attribute selectors — [Chris Coyier did an excellent write-up](http://css-tricks.com/attribute-selectors/) on them :) – Terry Aug 01 '14 at 00:32

1 Answers1

2

You probably wanted to write:

$("div[data-value='example1']").click(function(){
  alert('Hello')
});
PeterKA
  • 24,158
  • 5
  • 26
  • 48