dex dex - 2 months ago 34
Javascript Question

how to change word with javascript

<p class="author">
hipstr 發表在 <a href="http://www.pixnet.net/">痞客邦 PIXNET</a>
<a href="http://hipstr.pixnet.net/blog/post/146448884#comments">留言</a>(0)
<span class="author-views">人氣(
<span id="BlogArticleCount-146448884"></span>)
</span>
<a title="編輯" href="http://panel.pixnet.cc/blog/articleedit?blogarticle_id=146448884&blog=hipstr">
<img title="編輯" alt="edit this article" src="//s.pixfs.net/blog/images/choc/bedit.gif" border="0">
</a>
<a title="刪除" href="javascript:pix.delArticle(146448884, false);">
<img title="刪除" alt="delete this article" src="//s.pixfs.net/blog/images/choc/bdelete.gif" border="0">
</a>
</p>
<!-- .author //-->
<br>


hello, everyone.
I am trying to replace"留言" with "comments"

I've tried http://www.w3schools.com/jsref/jsref_replace.asp

but it didn't work. anyone can help out? thanks.

Answer

You can try to use this:

[].forEach.call(document.getElementsByClassName('author'), function(comment) {
    comment.innerHTML = comment.innerHTML.replace('留言', 'comments');
});
Comments