Home » Programming / Coding

innerText Does Not Work on FireFox – JavaScript

22 February 2011 1,801 views No Comment

If you happen to try use the JavaScript property innerText on an element you wont get it work with FireFox browser.

The reason is FireFox does not have a property innerText, rather they use a property called textContent.

There are many ways to solve this problem.

Option 1:
Use JQuery.
Example:
$(document).ready(function() {
$(‘myElementId’).text(“My Text or Whatever”);
});

Option 2:
Create a JavaScript function, and call it when you need.

function ChangeContent(elem, content) {
if (document.all)
elem.innerText = content;
else
elem.textContent = content;
}

There are many other ways as well.
____________________
From Webcosmo Webmaster Forum http://www.webcosmoforums.com/javascript-ajax/26917-innertext-does-not-work-firefox.html

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.