Eddie Welker.com

Hahaha.

  • Blog The blog
  • About About me

May 23, 2008
Posted by Eddie

Getting a button element’s value attribute (not innerHTML) in IE

After spending a small part of my evening debugging Javascript in IE (which is ALWAYS a pleasure), I found out one of my errors was a mistake I had made before… trying to access button.value in IE.  IE, of course, being IE, returns the innerHTML value of the button, instead of the value attribute.  Last time I ran into this, I used a class instead of value, and moved on with my life.  Tonight, I was feeling stubborn, and I found a better way…

target.value = target.getAttributeNode(‘value’).nodeValue;

I’m sure I’m about the millionth person to discover this, but I couldn’t find it anywhere using standard searches, so I thought I’d try to emphasize it here so others could find it. (Hopefully it’s not so common that everyone else knows it!)

At first, I used the following:

target.value =  target.attributes.getNamedItem(‘value’).nodeValue;

Then I looked at Flanagan’s Javascript: The Definitive Guide (using his amazon associates link),  where he states that IE implementation of the attributes array,”makes it impossible to use this feature portably.”  He doesn’t mention which version of IE (this specific line of code worked in IE6, IE7, and IE8a), but I figured I’d go with the more general version.

If you read this, I hope I could save you a bit of time.

P.S. – I used IE8a’s Debugger to help.  Here’s hoping they develop it further before the standard release.  It’s MUCH better than flying blind, but I can’t imagine a less helpful message than specifying an object in the console, and seeing “{…}”.

Comments Off

Posted Under ie ie8 javascript microsoft

No Comments Yet

You can be the first to comment!

Sorry, comments for this entry are closed at this time.

  • Me, elsewhere
    • tweets @ twitter
    • photos @ flickr
    • music @ last.fm
    • bookmarks @ delicious
    • articles @ google reader
    • events @ upcoming
    • location @ brightkite
    • updates @ friendfeed
    • books @ goodreads
    • me @ linkedin
    • me @ facebook
    • me @ github
    • me @ columbiaorchestra
  • My photos

    Oddly facing cat.MobyMore pastry.Black raspberry popoverPizzaAtlantic Avenue Beach
  • What I'm listening to
    • Charles Dutoit: Montreal Symphony Orchestra – Prokofiev: Love For 3 Oranges, Op. 33 - Scherzo
    • Charles Dutoit: Montreal Symphony Orchestra – Prokofiev: Love For 3 Oranges, Op. 33 - March
    • Charles Dutoit: Montreal Symphony Orchestra – Prokofiev: Love For 3 Oranges, Op. 33 - Infernal Scene
    • Charles Dutoit: Montreal Symphony Orchestra – Prokofiev: Love For 3 Oranges, Op. 33 - The Eccentrics
    • Bernard Haitink: Royal Concertgebouw Orchestra – Moderato
    • Bernard Haitink: Royal Concertgebouw Orchestra – Scherzo. Vivacissimo
    • Bernard Haitink: Royal Concertgebouw Orchestra – Prokofieff: Violinkonzert Nr.1 - Andantino
    • Bernard Haitink: Royal Concertgebouw Orchestra – Piano concerto #5; G Maj.; op. 55: V. Vivo
    • Bernard Haitink: Royal Concertgebouw Orchestra – Piano concerto #5; G Maj.; op. 55: IV. Larghetto
    • Bernard Haitink: Royal Concertgebouw Orchestra – Piano concerto #5; G Maj.; op. 55: III. Toccata

This site is using the Handgloves WordPress Theme
Designed & Developed by George Wiscombe

Subscribe via RSS