0

I have found that script :

<div id="hezi-gangina"></div>

<script>
 if(document.all)
 {
    document.getElementById('hezi-gangina').innerText="This line was created via innerText";
}
else
{
    document.getElementById('hezi-gangina').textContent="This line was created via textContent";
}
 </script>

Which makes me realize that innerText is not safe to use (...or am I wrong here)?

Which brings out 2 questions :

  1. Why should I use innerText anyways if it's not going to work properly on all browsers (unless the benefit of innerText is...) ?

  2. Is textContent is safe to use and would work in every scenario ?

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
davidmarko
  • 343
  • 3
  • 17
  • Where you say `safe` do you mean, cross-browser compatible? If so, what browsers are you targeting? – MDEV Mar 13 '15 at 17:15
  • @SmokeyPHP safe = cross-browser compatible. That ridiculous that you need to have several versions for each browser. – davidmarko Mar 13 '15 at 17:17

0 Answers0