Jump to content

Removing an element's style attribute?


Man In Tan

Recommended Posts

I need to dynamically add and remove styles but Javascript keeps choking. Through a series of alert()s and commenting things out, I've found the troublesome line. When I comment out the second line below, everything else works.

movefrom = document.getElementsByName('movefrom').item(0);document.getElementByName(movefrom.value).item(0).removeAttribute('style');

I've tried several variations too, such as:

movefrom = document.getElementsByName('movefrom').item(0);test_0 = movefrom.value;test_1 = document.getElementByName(test_0).item(0);test_1.removeAttribute('style');

So far, I've been able to add styles just fine, but I can't remove them. Any ideas? EDIT: I've been fiddling with this for hours, but as soon as I post, I figure it out. "getElementByName" should be "getElemenstByName". Haha. Sorry to have wasted your time.

Edited by Man In Tan
Link to comment
Share on other sites

where you checking your error console? You probably would have gotten an error saying that getElementByName is not defined, or something to that affect.

Link to comment
Share on other sites

"Error console"? Never heard of it. I assume it outputs errors, similar to PHP, but for JavaScript? That would be very helpful. I'll see what I can find on my local search engine. www.projectwonderful.com/ad_display.js:1TypeError: Result of expression 'document.write' [undefined] is not a function. Oh, snap! This is great! Thanks for sharing you wisdom! I should be much more effective with JavaScript, now. One of the reason I rarely use it is that I couldn't tell what happened when things went wrong, but it looks like that's over. You have my deepest gratitude.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...