How to Replace Some Specific words in webpage with javascript | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

How to Replace Some Specific words in webpage with javascript

Here is a code in my webpage; <div class="class_1"> <p>Copyright © 2017. Created by <a href="http://facebook.com/example123" target="_blank">Example 123</a>. Powered by <a href="http://www.example123.com" target="_blank">ExamPleXYZ</a>.</p> </div> Now is want to change 2017 into 2018 and Example 123 into change123 and ExampleXYZ into changexyz Note: only Use javaScript not jquery

7th Jul 2018, 2:38 PM
Muhammad Irfan ✓
Muhammad Irfan ✓ - avatar
3 Answers
+ 2
Hello there try this <!DOCTYPE html> <html> <body> <div class="class_1"> <p>Copyright © <script>document.write(new Date().getFullYear())</script>. Created by <a href="http://facebook.com/example123" target="_blank">Example 123</a>. Powered by <a href="http://www.example123.com" target="_blank">ExamPleXYZ</a>.</p> </div> <script> var txt=document.querySelectorAll(".class_1 p")[0]; txt.innerHTML=txt.innerHTML.replace('Example 123','change123').replace('ExamPleXYZ','changexyz'); </script> </body> </html>
7th Jul 2018, 4:04 PM
ᴋᵘⁿᵃˡ
ᴋᵘⁿᵃˡ - avatar
+ 2
thanks bro
7th Jul 2018, 11:35 PM
Muhammad Irfan ✓
Muhammad Irfan ✓ - avatar
0
In simple terms. Select element by id/tag/class then change the thing you wanted to by id_of_var.thing_needs_tobe_changed = by copying the original but change the specific thing that you wanted to.
10th Nov 2018, 12:25 PM
Գաբրիել Ադամյան
Գաբրիել Ադամյան - avatar