1

I have the following bit of code shown below:

<div class="timer" id="timer"><img src="http://i.imgur.com/87XaOWA.png"><p class="close-message" id="close-message"></p></div>

Now, when the page is viewed in Internet Explorer I want the div to be removed.

Since IE doesn't support the .remove() function I have found the following solution to circumvent the problem here. I have also found the following fiddle that can detect which browser is being used to view the page.

I've tried the following two if statements to remove the div tag when viewed in IE to no avail:

// Internet Explorer 6-11
var isIE = /*@cc_on!@*/false || !!document.documentMode

if (isIE = false) {
jQuery("#timer").eq(i).remove();
}

and

// Internet Explorer 6-11
var isIE = /*@cc_on!@*/false || !!document.documentMode

if (isIE = false) {
var node = document.getElementsById('timer')[i];
node.parentNode.removeChild(node);
}

What am I doing wrong? Individually the two components work fine, but when I try to use them together they don't work.

1 Answers1

2

Your first error is:

if (isIE = false) {

you need to use a double equal sign for comparing, and in your case it should be:

if (isIE == true) {

The second error is:

document.getElementsById('timer')[i]

change it to:

document.getElementById('timer')

var isIE = /*@cc_on!@*/false || !!document.documentMode;

if (isIE == true) {
    var node = document.getElementById('timer');
    node.parentNode.removeChild(node);
}

//
// in jQuery: remove: .eq(i)....
//
if (isIE == true) {
  jQuery("#timer").remove();
}
<div class="timer" id="timer"><img src="http://i.imgur.com/87XaOWA.png"><p class="close-message" id="close-message"></p></div>
gaetanoM
  • 41,594
  • 6
  • 42
  • 61
  • Guess I didn't catch my `isIE = false` mistake because my JS wasn't inside the `div` tag in my code which contains the `#timer`. But for whatever reason while this works in my code it doesn't work in JSFiddle which if it had worked I might of caught my mistake before posting this question. – ChippeRockTheMurph Sep 29 '17 at 17:39
  • @ChippeRockTheMurph You may consider to wrap your code in [DOMContentLoaded](https://developer.mozilla.org/it/docs/Web/Events/DOMContentLoaded). – gaetanoM Sep 29 '17 at 17:42