data 属性を適用したい div.textBox がたくさんあります。
これが私が終わらせたいものです:
<div class="text" data-stellar-ratio="2">
私はもう試した :
document.getElementByClassName('text').dataset.stellar.ratio = "2";
しかし、それは機能していません...
ヘルプ!
data 属性を適用したい div.textBox がたくさんあります。
これが私が終わらせたいものです:
<div class="text" data-stellar-ratio="2">
私はもう試した :
document.getElementByClassName('text').dataset.stellar.ratio = "2";
しかし、それは機能していません...
ヘルプ!
スペルがgetElementsByClassName
間違っているため、要素のコレクションを繰り返し処理して、に変更する必要がありstellar.ration
ますstellarRatio
。
var eles = document.getElementsByClassName('text');
for (var x = 0; x < eles.length; x++){
eles[x].dataset.stellarRatio = "2";
}
setAttribute は、すべてのブラウザーで完全に機能するわけではありません。http://www.w3schools.com/jsref/met_document_createattribute.aspには、確かにうまく機能する例があります。
var att=document.createAttribute("whatever");
att.value="someting";
document.getElementById('mydivid').setAttributeNode(att);