Javascript innerText alternative textContent for Mozilla Firefox

Since you are here i assume that you have already tried innerText for Mozilla Firefox but failed. Because in Mozilla Firefox the property innertext does not work. One alternative may be innerHTML. I found that most of the developers suggest to use innerHTML instead of innerText but my thought is different because if you use innerHTML instead of innerText then you may experience rendering problem due to your CSS. So i will suggest you to use textContent instead of innerText for Mozilla Firefox & it will resolve your all problems. So first detect browser by javascript and then use innerText and textContent respecively like below:

<script type="text/javascript">
    function TransferValue() {
        var txtInfo = document.getElementById('<%= txtInfo.ClientID %>');
        var lblInfo = document.getElementById('<%= lblInfo.ClientID %>');
        if (document.all) {

            lblInfo.innerText = txtInfo.value;
        else {
            lblInfo.textContent = txtInfo.value;
        return false;

To complete the example please add below ASP.Net Server Side Controls & Invoke TransferValue:

<asp:TextBox ID="txtInfo" runat="server"></asp:TextBox>
<asp:Button ID="cmdTransfer" runat="server" OnClientClick="return TransferValue();" Text="Transfer" />
<asp:Label ID="lblInfo" runat="server"></asp:Label>

Note: Code is same for both C# & VB.Net


Download Code Example C#        Download Code Example VB.Net

Leave a Reply

Your email address will not be published. Required fields are marked *

AlphaOmega Captcha Classica  –  Enter Security Code