happysmile
happysmile

Reputation: 7777

javascript fails in firefox but works fine in IE

my code

function   hide()
{
  var lblclear= document.getElementById("<%=Label1.ClientID%>"); 
  if(lblclear!= null) {
    lblclear.value="";
    lblclear.innerText="";
    lblclear.outerText="";
  }
}

on button click i am calling this function

the above function works fine in IE it is clearing my label text value in firefox browser it is not clearing my label text value

can any one help me out thank you

Upvotes: 0

Views: 949

Answers (3)

Anwar Chandra
Anwar Chandra

Reputation: 8648

innerText will only work in IE, for other browser you should use innerHTML

function   hide()
{
  var lblclear= document.getElementById("<%=Label1.ClientID%>"); 
  if(lblclear!= null) {
    lblclear.value="";

    if (document.all) { // check if IE
      lblclear.innerText="";
      lblclear.outerText="";
    }
    else{  // other browsers
      lblclear.innerHTML="";
      lblclear.outerHTML=""; // updated. thanks @cdmckay
    }

  }
}

please check working example

Upvotes: 1

James Black
James Black

Reputation: 41848

Your problem is that innerText and outerText is not supported on Firefox.

http://www.java2s.com/Tutorial/JavaScript/0460__DOM-Node/GetouterTextvalueforatagFirefoxdoesnotsupporttheouterText.htm

In order to hide this you can remove it (as that looks like what you are doing) or, preferably, using css, either the element.style properties or set className, but you can set the visibility or display to a value that does what you want.

Upvotes: 3

Windows programmer
Windows programmer

Reputation: 8075

Add a call to Alert in your function to see if your function is even getting called.

Upvotes: 0

Related Questions