0

I need to remove the class YoPowered, it is the class of a div. I need it to be removed.

Can't seem to figure this one out.

Xander
  • 387
  • 3
  • 9
  • 29
  • possible duplicate of [Remove CSS class from element with JavaScript (no jQuery)](http://stackoverflow.com/questions/2155737/remove-css-class-from-element-with-javascript-no-jquery) – haim770 Aug 26 '13 at 20:39
  • Remove the class on the element or remove all elements with that class? – plalx Aug 26 '13 at 20:39
  • document.querySelectorAll() is 90% as good as jQuery for dom selection. – dandavis Aug 26 '13 at 20:42

1 Answers1

1
var elems = document.getElementsByClassName("YoPowered");

for(var i = elems.length - 1; i >= 0; i--) {
  elems[i].className = elems[i].className.replace(/YoPowered/, '');
}

You could optionally replace the document.getElementsByClassName("YoPowered") with document.querySelectorAll('.YoPowered')

See http://www.quirksmode.org/dom/w3c_core.html for compatibility if that's an issue.

Rich
  • 2,805
  • 8
  • 42
  • 53
  • `getElementsByClassName` returns a live [HTMLCollection](https://developer.mozilla.org/en-US/docs/Web/API/HTMLCollection?redirectlocale=en-US&redirectslug=DOM%2FHTMLCollection). Your code will not work properly. – plalx Aug 26 '13 at 20:54
  • I see your point, edited to handle live collection – Rich Aug 26 '13 at 21:25