tags:

views:

88

answers:

3

hi, 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

A: 

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

Windows programmer
+1  A: 

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

Anwar Chandra
Don't you mean `outerHTML` for the second line of the `else`?
cdmckay
@cdmckay yes I mean outerHTML. updated. thanks
Anwar Chandra
+3  A: 

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.

James Black
+1 for CSS suggestion
Carlos Lima