-1

I have a few html object with the same data-id number (data-id=9)

Is it possible to change the style of these objects by the condition data-id=9 in jquery?

asdfasdf
  • 211
  • 2
  • 4
  • 9
  • `$("div").filter("[data-id=9]").addClass("style-class")` – Aliaksei Bulhak Aug 13 '14 at 11:08
  • Sure, use an [Attribute Selector](http://api.jquery.com/attribute-equals-selector/) – George Aug 13 '14 at 11:10
  • possible duplicate of [Selecting element by data attribute](http://stackoverflow.com/questions/2487747/selecting-element-by-data-attribute) and [many others](https://www.google.com/#q=jquery%20select%20by%20attribute%20site:stackoverflow.com). – George Aug 13 '14 at 11:11

1 Answers1

1

try as below, it is a example

HTML

<div data-id="9">Hello</div>
<div data-id="9">Hello</div>
<div data-id="9">Hello</div>
<div data-id="10">Hello</div>

JS

$('div[data-id="9"]').addClass("hi");

DEMO

Amit
  • 15,217
  • 8
  • 46
  • 68