1 Replies - 454 Views - Last Post: 11 November 2013 - 06:47 AM

#1 CY5  Icon User is offline

  • D.I.C Regular

Reputation: 12
  • View blog
  • Posts: 350
  • Joined: 28-September 12

how to get div using .data(key,value) method

Posted 11 November 2013 - 05:19 AM

I have several div tags with same class name and no id every div tag have different data() value. so i wanted to select any one div tag through data() method and add a class to it. Please help
Answer can be in (Jquery/Javascript)

<div class="g" style="left: 50px; top: 0px;" data-pattern="orange1">  </div>
<div class="g" style="left: 230px; top: 0px;" data-pattern="orange1">  </div>
<div class="g" style="left: 410px; top: 0px;" data-pattern="water1">  </div>
<div class="g" style="left: 590px; top: 0px;" data-pattern="water1">  </div>
<div class="g" style="left: 50px; top: 174px;" data-pattern="cherry1">  </div>
<div class="g" style="left: 230px; top: 174px;" data-pattern="guava1">  </div>
<div class="g" style="left: 410px; top: 174px;" data-pattern="app1">  </div>



Is This A Good Question/Topic? 0
  • +

Replies To: how to get div using .data(key,value) method

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3577
  • View blog
  • Posts: 10,442
  • Joined: 08-June 10

Re: how to get div using .data(key,value) method

Posted 11 November 2013 - 06:47 AM

you could try to match it like any other attribute: div[data-pattern='value'].
Was This Post Helpful? 2
  • +
  • -

Page 1 of 1