innerText' works in IE, but not in Firefox
Firefox uses the W3C-compliant textContent property.
I'd guess Safari and Opera also support this property.
Why is .innerText not working in Firefox?
innerText
is the "old Internet Explorer" way of doing it.
Try textContent
instead. Ideally you should use elem.textContent || elem.innerText
, but if you're using jQuery you can just do jQuery("#the_id_here").text()
.
children.innerText is not working in firefox
Use textContent
instead of innerText
Javascript with Firefox innerText issue
While innerText
is non-standard, it significantly differs from textContent
, because first one is doing pretty printing (for example, <br/>
are converted to new lines), while second one - is not.
So, while common wisdom is to use:
var toUsername = anchor.innerText || anchor.textContent;
or some kind of wrapper, it can probably be smarter to just use jQuery's .text
or its analog from other library you are using.
innerHTML works in IE and Firefox, but not Chrome
You should use some modern Javascript library. It guards you from many of those small differences between browsers. I like jQuery.
So, with jquery your code
window.onload = function() {
var url = "http://----.freeiz.com/gbSales/sales.json";
var request = new XMLHttpRequest();
request.open("GET", url);
request.onload = function () {
if (request.status == 200) {
updateSales(request.responseText);
}
};
request.send(null);
}
function updateSales(responseText) {
var salesDiv = document.getElementById("sales");
salesDiv.innerHTML = responseText;
}
becomes
$(document).load(function() {
var url = "http://----.freeiz.com/gbSales/sales.json";
$.get(url, {}, function(data) {
$('#sales').html(data);
});
});
Shorter, cleaner and works in all browsers!
Inline JavaScript works in Chrome but not in Firefox
The issue comes from innerText
.
See: 'innerText' works in IE, but not in Firefox
You should use jQuery or use innerHTML
.
Related Topics
How to Obfuscate (Protect) JavaScript
JavaScript Object: Access Variable Property by Name as String
How to Split a String, Breaking At a Particular Character
Using the Variable "Name" Doesn't Work With a Js Object
What Is the "Right" Json Date Format
What's the Prettiest Way to Compare One Value Against Multiple Values
JavaScript - Sort Array Based on Another Array
How to Get Function Parameter Names/Values Dynamically
Http Get Request in JavaScript
Why Is the Method Executed Immediately When I Use Settimeout
Find the Min/Max Element of an Array in JavaScript
Difference Between a Function Expression VS Declaration in JavaScript