Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

textContent.replace not working within my function

Tags:

javascript

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 compatibility 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 welcome.

Below the full code in Jsfiddle:

http://jsfiddle.net/r7bL6vLy/123/

like image 925
Asperger Avatar asked Jul 16 '26 17:07

Asperger


1 Answers

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

info.textContent = info.textContent.replace('Title', "replaced");
like image 99
dfsq Avatar answered Jul 19 '26 06:07

dfsq



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!