I have an element on several pages that looks like this. This is on several pages and I want to update the '2020' part to be '2021' using Javascript.
//Get string var str = document.querySelector('#lp-pom-text-14 > p').innerHTML; //Remove last 4 characters of the string var strRemoved = str.slice(0, str.length - 4); // Add 4 new characters of the string var newString = strRemoved + '2021'; // Set new string as innerHTML document.querySelector('#lp-pom-text-14 > p').innerHTML = newString;
<div id="lp-pom-text-14"> <p>Johnny's Pizza Shop. All Rights Reserved. 2020</p> </div>
1.4m articles
1.4m replys
5 comments
57.0k users