Using the innerText Property in Firefox
2008-06-30 13:05
435 查看
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):
That’s it. Hope it helps
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
相关文章推荐
- Using the innerText Property in Firefox
- How to get the password text in a text with password property from another process using C++ - 用C++如何从不同进程获取密码框文本
- Fw:Managing View State in ASP.NET 4 Using the New ViewStateMode Property
- Storing text in the clipboard using Silverlight 2
- 使用cocapods报错 [!] Your Podfile has had smart quotes sanitised. To avoid issues in the future, you should not use TextEdit for editing it. If you are not using TextEdit, you should turn off smart quotes
- firefox 下 'innerText' works in IE, but not in Firefox
- Why is .innerText not working in Firefox?
- Creating a Web Control with an Expandable Property in the Designer by Using C#.
- make the innerText in the html element can not be selected
- Specifying special characters in the text property
- Using the Telerik Rich Text Editor In Visual Studio LightSwitch
- Parsing Failure in config.xml: java.lang.IllegalArgumentException: In production mode, it's not allowed to set a clear text value to the property
- How to change the text color of the selected property sheet tab in Visual C++
- Saving the entire git diff between two commits in a text file
- Pixel Width of the text in a UILabel
- Warning: Using a password on the command line interface can be insecure.解决办法
- Some text formatting may have changed in this file because the maximum number of fonts was exceeded解决办法
- Data Structures in the Andrew Text Editor
- using the Connector/J connection property 'autoReconnect=true' to avoid this problem
- Point-in-Time (Incremental) Recovery Using the Binary Log