Reputation:
I have used innerHtml in my java based web application. JavaScript works fine with Mozilla Firefox but it is not working in InternetExplorer.
Could you please tell me how to make it work in Internet Explorer too. or what is substitute of innerHTML in IE.
Code is:
function show() {
if('number' == typeof this.rowIndex) {
var rn = this.rowIndex;
var cell = tableRows[rn].cells;
employeeCode = cell[0].innerHTML;
//..........
}
}
Thank and regards
Upvotes: 1
Views: 1126
Reputation: 669
You first need to check if the browser is using internet explorer then get the version. after you have the browsers version you can use an if statement to tell it to use InnerText for IE and InnerHTML for the rest of the browsers.
InnerText is the alternate way of InnerHTML for Internet Explorer. Hope this helps.
if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
var ieversion = new Number(RegExp.$1) // capture x.x portion and store as a number
}
//detect if IE version is greater than 1 then deletes row content
if (ieversion>=1) {
row.innerText = '';
} else {
row.innerHTML = '';
}
Upvotes: 0
Reputation: 11
innerHTML, to be cross-browser, needs something like this :
<script type="text/javascript">
function show (where,what) {
var ie = document.all; // Internet Explorer
var ns = document.getElementById && !document.all; // Firefox, Netscape, other browsers
if(ie) {
eval("document.all."+where).innerHTML = what; }
else if(ns) {
document.getElementById(where).innerHTML = what; }
}
</script>
<a href="javascript:show('display','Hallo')">try</a>
<div id="display"></div>
As I found in http://usenet.manifestinteractive.com/manifestElementControl.html?/usenet/manifestElementControl.html
Upvotes: 1
Reputation: 268344
Using jQuery eliminates problems like this in nearly all cases. It handles the minor differences between major browsers so you can do simple things like:
$("div.summary").html(); /* Gets HTML from <div class="summary"> */
$("div.summary").html("Hello"); /* Sets the HTML */
Upvotes: 7