I have a span tag with 34 randomly generated letters and numbers. I will like 14 characters after the first 10 characters to be replaced with X. Please how can this be done with javascript? Thanks.
From This:
<span>1KThBTGGQgT7VsZjYSgucdHMCUJrw5UdrJ</span>
To This: 1KThBTGGQgxxxxxxxxxxxxxxCUJrw5UdrJ
CodePudding user response:
you can probably also do this with regex which might be a better solution
//To This: 1KThBTGGQgxxxxxxxxxxxxxxCUJrw5UdrJ
let text = document.querySelector('span')
let left = text.innerText.substr(0,10)
let center = "xxxxxxxxxxxxxx"
let right = text.innerText.substr(24)
let newText = left center right
text.innerText = newText
<span>1KThBTGGQgT7VsZjYSgucdHMCUJrw5UdrJ</span>