Jump to content

IE 7 sucks - but what else is new?


brittny85

Recommended Posts

I'm working on a website for a client and I need to change the ID of the body if a certain condition is met.  I have code that works great in all browsers... except IE 7.  Anyone know why the following line of code would crash IE 7, and no other browser?  Any ideas of a different way to make this work?

 

document.getElementById('t2').id

 

Thanks!

-Brittny

Link to comment
https://forums.phpfreaks.com/topic/193021-ie-7-sucks-but-what-else-is-new/
Share on other sites

So I got some help from a friend, but I'm no closer to figuring out how to do what I need to do.  We changed the code to:

var docid = document.getElementById('t2');
docid.id = 'home';

 

The page only crashed when I added in the second line, so it's definitely the changing the id that is crashing IE, not the getting the element.  Any thoughts on what I could do otherwise?

Well, I didn't really figure out why IE does this or how to make it actually change the ID of an object using Javascript, however I did come up with a passable workaround.  Since I was just using the IDs to apply different CSS styles I changed tactics and added a class name instead.  I then modified my CSS to reflect this change. 

 

document.getElementById('full_page').className = 'home';

 

Anyways, hopefully this is helpful to someone else down the line as well.

I thought about using JQuery, but it isn't really practical for the application at hand.  The tool my client is having me use won't allow me to import external files, so I'd have to paste the whole JQuery library in a script tag in the header, which would make editing the template a little unwieldy.  But that's definitely a good idea for people that don't have this limitation!  Thanks :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.