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 “{…}”.

No Comments

Posted Under ie ie8 javascript microsoft

No Comments Yet

You can be the first to comment!

Leave a comment

You must be logged in to post a comment.

  • 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 @ djangopeople
    • me @ facebook
    • me @ github
    • me @ columbiaorchestra
  • My photos

    On vacation: @MobyCat.At the beach.Getting pizza.Fishing reelBuilding profileGrass
  • What I'm listening to
    • Siouxsie and the Banshees – Suburban Relapse
    • Siouxsie and the Banshees – Nicotine Stain
    • Siouxsie and the Banshees – Metal Postcard
    • Siouxsie and the Banshees – Mirage
    • Siouxsie and the Banshees – Helter Skelter
    • Siouxsie and the Banshees – Carcass
    • Siouxsie and the Banshees – Overground
    • Siouxsie and the Banshees – Jigsaw Feeling
    • Siouxsie and the Banshees – Pure
    • Leon Redbone – If I Could Be With You

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

Subscribe via RSS