zoukankan      html  css  js  c++  java
  • Using the innerText Property in Firefox

    I’ve read on different forums questions of people asking how they can make the innerText property work in Firefox. Many have suggested to use the innerHTML property instead, but that would not be useful because, obviously, the HTML tags would be either rendered or displayed (an example of the latter would be if we want such text to be displayed in a textarea or text field) giving undesired effects.

    Well, in short, Firefox does not support the innerText property. Instead, it supports the textContent property.

    So, you could ’sniff’ what browser the user is using and use the correct property accordingly.
    So, you could check for the browser’s feature support to use the correct property accordingly (this is better than sniffing ;))

    Example (updated):

    if(document.all){
    document.getElementById('element').innerText = "my text";
    } else{
    document.getElementById('element').textContent = "my text";
    }
    

    That’s it. Hope it helps ;)

    J

  • 相关阅读:
    查找第K小数
    比较奇偶数个数
    哈夫曼树练习
    数字转二进制数练习
    随笔
    字符串反码(练习)
    eclipse构建maven的web项目
    mysql中的一些操作语句,留存
    urllib2功能说明
    Python-第三方库requests详解
  • 原文地址:https://www.cnblogs.com/goody9807/p/1071976.html
Copyright © 2011-2022 走看看