PDA

View Full Version : MSIE Doesn't support getelementbytag..any ideas?



tedteeter
09-05-2013, 01:19 AM
Greetings, September 4th 2013

I am presently attempting to alter multiple div styles from hidden to visible as I select a button that loads a specific id to a function and the button id serves as id for the div as well and all the div's appear as they should in "Fire Fox", "Safari" However, I've learned that MSIE doesn't support the getelementByTag and other routines reference the div ids so changing accordingly is out as an option. I've attempted document.all, however, the result hasn't worked as a variable in the id of getelementbyid rather it reports as null !...Any ideas? Again, the id's of the div's are the identical to the id's of the css buttons All goes well however "tag.style.visibility" isn't recognized and null..I've included some messy code below

Appreciatively,
Ted


var tag, tags;

//alert(document.all.length);
for(i = 0; i < document.all.length; i++)
{
tag = document.all(i).getAttribute('id');
tag2 = document.all(i).getAttribute('name');
//alert(tag+" <==IE==> "+tag2+" ==choosen one===>"+thechosenone.id);
if(tag==thechosenone.id && tag2=='contentarea'){
alert(tag+"<< == >>"+thechosenone.id);
//tag.style.visibility = 'visible';
//tag2.style.visibility = 'hidden';
document.getElementById('contentarea1').style.visibility = 'visible';
//alert(tag(i).style.visibility);
if (tag==thechosenone.id) {
alert('in here');
if (tag.style.visibility == 'hidden') {
tag.style.visibility = 'visible';
}
else {
tag.style.visibility = 'hidden';
}
}else {
//if(tag2=='contentarea'){
tag.style.visibility = 'hidden';
// }
}
//alert(tag+" <==IE==> "+tag2);
//alert('match');
//tags = tags + "\r" + tag;
}
}

traq
09-05-2013, 01:54 AM
... I've learned that MSIE doesn't support the getelementByTag
Right. No other browser does, either, AFAIK. getElementsByTagName (https://developer.mozilla.org/en-US/docs/Web/API/element.getElementsByTagName#Browser_Compatibility) might be what you're looking for?

Beyond that, this:

I am presently attempting to alter multiple div styles from hidden to visible as I select a button that loads a specific id to a function and the button id serves as id for the div as well
...makes me suspect you might be trying to assign the same id to multiple elements? This is illegal in HTML (every id must be unique - if other browsers are allowing this, then -WWNC- IE is the one that got it right). You should use a classname or data- attribute instead.

You might also consider making a reduced test case (http://css-tricks.com/reduced-test-cases/) using an online tool like jsfiddle (http://jsfiddle.net) to help us understand your problem further.

tedteeter
09-05-2013, 02:54 AM
traq,

You are correct it is the "getElementsByTagName" and you are further correct that I may be confusing the id's so I did attempt applying multiple id's to the div's as it is legal an has worked in the past. The below is working out great! However the for loop isn't keeping the others hidden as I click through the buttons. The id's correctly allow the appearance of the div however the previously invoke div doesn't disappear and they simply stack atop each other?...any ideas?

document.all(i).style.visibility='visible';

tedteeter
09-05-2013, 04:40 AM
traq,

the below is what I have and the divs appear, however, they yet to disappear while at the bottom of the routine there is an if statement commented out which retains an element for index increment that will change the to hidden. Any ideas?

Appreciatively,
ted

var tag, tags;
// or you can use var allElem=document.all; and loop on it
tags = "The tags in the page are:"
//alert(document.all.length);
for(i = 0; i < document.all.length; i++)
{
tag = document.all(i).getAttribute('id');
tag2 = document.all(i).getAttribute('name');

if(tag==thechosenone.id && tag2=='contentarea'){

if (tag==thechosenone.id) {
alert(document.all(i).style.visibility);
if (document.all(i).id==thechosenone.id){
document.all(i).style.visibility = 'visible';
}
else {
document.all(i).style.visibility = 'hidden';
}

}else {
//if(tag2=='contentarea'){
//document.all(i).style.visibility = 'hidden';
document.all(i).style.visibility='hidden';
}
//if(i==40){
//document.all(38).style.visibility='hidden';
//}

}
}

traq
09-05-2013, 01:48 PM
I've got to run right now but I'll look at your code when I get home this afternoon. John might be able to help as well.

tedteeter
09-05-2013, 11:36 PM
traq, September 5th 2013

Okay! after having walked away from the project for a night I reviewed the code an completed a simplistic fix to the above "Messy Code" and have included it below for readers that may become confused as I did!...Your assistance is very valued and appreciated, much thanks :-)
Ted

var tag, tags;
// or you can use var allElem=document.all; and loop on it
tags = "The tags in the page are:"
for(i = 0; i < document.all.length; i++)
{
tag = document.all(i).getAttribute('id');
tag2 = document.all(i).getAttribute('name');
if(tag==thechosenone.id && tag2=='contentarea'){
document.all(i).style.visibility='visible';
}else{
if(tag2=='contentarea'){
document.all(i).style.visibility='hidden';
}

}
}