Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
129
rated 0 times [  133] [ 4]  / answers: 1 / hits: 20533  / 12 Years ago, wed, february 13, 2013, 12:00:00

I've got a bunch of div.textBox that I want to apply data attribute to it.



Here's what I want to end up with :



<div class=text data-stellar-ratio=2>


I've tried :



document.getElementByClassName('text').dataset.stellar.ratio = 2;


But it's not working...



Help!


More From » javascript

 Answers
3

As documented



The getElementsByClassName method of Document interface returns an
array-like object of all child elements which have all of the given
class name(s).



More precisely, a NodeList is returned and can be accessed as an array. The first element the selector finds is accessed via index 0.


document.getElementsByClassName('text')[0].setAttribute('data-stellar-ratio', '2')


[#80241] Tuesday, February 12, 2013, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
zariahdiamondz

Total Points: 649
Total Questions: 109
Total Answers: 88

Location: Tajikistan
Member since Thu, Apr 14, 2022
2 Years ago
;