最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - textContent.replace not working within my function - Stack Overflow

programmeradmin4浏览0评论

I dont know why this is the case but my replace does not work. It is somehow unusual considering my syntax is correct.

info.textContent.replace('Title', "replaced"); 

where info is the variable that stores an element. It should actually replace all instances of Title with "replaced". I prefer not using innerText due to patibility issues and innerHTML due to security risks. textContent is supported by firefox and I have no idea what is going on.

I would appreciate some insight. I am learning javascript and tips for best practice are wele.

Below the full code in Jsfiddle:

/

I dont know why this is the case but my replace does not work. It is somehow unusual considering my syntax is correct.

info.textContent.replace('Title', "replaced"); 

where info is the variable that stores an element. It should actually replace all instances of Title with "replaced". I prefer not using innerText due to patibility issues and innerHTML due to security risks. textContent is supported by firefox and I have no idea what is going on.

I would appreciate some insight. I am learning javascript and tips for best practice are wele.

Below the full code in Jsfiddle:

http://jsfiddle/r7bL6vLy/123/

Share Improve this question asked Sep 14, 2015 at 19:00 AspergerAsperger 3,22211 gold badges59 silver badges106 bronze badges 0
Add a ment  | 

1 Answer 1

Reset to default 8

It works, it's just replace method returns new string you need to assign back:

info.textContent = info.textContent.replace('Title', "replaced");
发布评论

评论列表(0)

  1. 暂无评论