1



Is there a way to add a custom HTML attribute to say a DIV element and then be able to use CSS attribute selectors with it in IE?

Example that works (turns into green) in FF but not in IE:

in JavaScript:

element.setAttribute('newAttr', 'green');


in CSS:

[newAttr=green] {
   background-color: green;
}


Kind regards

dsgriffin
  • 66,495
  • 17
  • 137
  • 137
geeko
  • 2,649
  • 4
  • 32
  • 59
  • http://stackoverflow.com/questions/710275/how-to-add-update-an-attribute-to-an-html-element-using-javascript Above link is provide the answer for you... – Ksnrg Feb 05 '13 at 10:06
  • @Ksnrg: I am really interested in accessing these created attributed using CSS attribute selectors in IE – geeko Feb 05 '13 at 11:02

2 Answers2

0

You could do this:

<div id="some" data-newattr="green"></div>
Mark
  • 6,762
  • 1
  • 33
  • 50
0
var attribute = document.createAttribute("size");
attribute.nodeValue = "15"
document.getElementById("text").setAttributeNode(attribute);
Ksnrg
  • 147
  • 1
  • 2
  • 9