pavan
pavan

Reputation: 217

all() function not working in Firefox

In IE below line is working . popup is a div element.

popup.all("submenu").innerHTML = "";

But in other browsers below error is coming

popup.all is not a function.

Is there any alternative for all function in other browsers.

Please suggest me. Thanks.

Upvotes: 0

Views: 595

Answers (4)

Alex Ackerman
Alex Ackerman

Reputation: 1341

try this:

var popup=document.getElementById('popup');
for (i in popup.childNodes) {
   if (popup.childNodes[i].nodeType == 1) {
       popup.childNodes[i].innerHTML = '';
   }
}

Upvotes: 0

Anthony Grist
Anthony Grist

Reputation: 38345

Use document.getElementById(elementName).innerHTML = whatever; instead.

Upvotes: 0

Álvaro González
Álvaro González

Reputation: 146588

In all browsers (including Internet Explorer) you are expected to find items by their location in the DOM tree (I'm assuming it's a DOM node given the .innerHTML property). You can use, for instance, document.getElementById() and document.getElementsByTagName(). Of course, you can always store references to nodes in regular variables.

Upvotes: 1

Ashwin Krishnamurthy
Ashwin Krishnamurthy

Reputation: 3758

All method is not supported by most browsers. Except IE ofcourse. Test for document.getElementById if this is false then use the "all" method.

Upvotes: 1

Related Questions