Another Newbie Question: I am attempting to completely remove a class from the DOM when the screen.width is smaller than or equal to 320 px. Attempting this without specifying a screen width works just fine. The class is removed from the page, but when I attempt to specify the conditional screen width it does not. Can anyone help me out here? This is what I have:
<div class="poison">Poison Text</div>
<script>
var p = document.getElementsByClassName('poison');
var cstr = "poison";
var poison = screen.width;
if (poison <= 320) {
(var i = p.length; --i >= 0;) {
var n = p[i];
while (n.className.split(" ").indexOf(cstr) == -1) {
n = n.parentNode;
}
n.parentNode.removeChild(n);
}
}
</script>
forloop(var i = p.length; --i >= 0; )and forgot thefor(var i=p.length; --i>=0;)supposed to be doing? Is this anifstatement? Aforloop? In its current state this snippet of code will not achieve anything.whileloop. You already know that thenelement has that class, so why attempt to traverse through its ancestors?