Wednesday, October 12, 2011

Firefox no likey innerText

PROBLEM: You've gotten your hands dirty on some client side coding a.k.a. javascript, and its working fine in all browsers like IE and Chrome but not in Firefox. The offending line is something like:

" var iCurrent = parseInt(document.getElementById('" + lblWordCount.ClientID + "').innerText);" +
SOLUTION: Use innerHTML instead of innerText e.g.

//Note: Don't use innerText as it isn't supported by Firefox
" var iCurrent = parseInt(document.getElementById('" + lblWordCount.ClientID + "').innerHTML);" +

CAVEATS: Ok, so after a bit more googling (http://stackoverflow.com/questions/1359469/innertext-works-in-ie-but-not-in-firefox) it's definitely not the preferred solution and has issues itself, but for my simple scenario it worked ok. Ideally I should probably be using some jquery or accessing the DOM properly etc. I'm open to here better solutions.

No comments:

Post a Comment