Pages

Thursday, June 12, 2008

textContent not working in IE, use innerHTML

My javascript is working fine in FireFox and Safari but when use IE (mine is IE7), it's give me problem [Undefined].

.........................
..........................
this.post[i].head = this.posts[i].getElementsByTagName('a')[0];
this.post[i].title = this.post[i].head.textContent;
.......................
......................

Spend hours to check on the issue and finally found a very simple way to solve it, use innerHTML instead of using textContent.

.........................
..........................
this.post[i].head = this.posts[i].getElementsByTagName('a')[0];
this.post[i].title = this.post[i].head.innerHTML;
.......................
......................


problem solve.

2 comments:

  1. Be careful with .innerHTML too!

    IE has a few bugs with .innerHTML that you'll want to be aware of.

    See this site:
    http://webbugtrack.blogspot.com/2007/12/bug-210-no-innerhtml-support-on-tables.html

    http://webbugtrack.blogspot.com/2008/03/bug-165-dynamic-pre-population-fails-in.html

    http://webbugtrack.blogspot.com/2008/01/bug-or-feature-round-one.html

    http://webbugtrack.blogspot.com/2007/10/bug-124-setting-innerhtml-problem-no1.html

    http://webbugtrack.blogspot.com/2007/08/bug-274-dom-methods-on-select-lists.html

    ReplyDelete
  2. may to use node.innerText too

    ReplyDelete

Please don't spam!