Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

220
Views
How to change the value of innerText at a particular index?

I am trying to change the string displayed in the frontend by using a function in javascript.

let displayword = document.getElementById("displayword”)
    console.log(displayword.innerText)     //apple

Say, I want the change the letter “l” to something else say “i” but keep the rest of the letters unchanged how do I go around this?

Things I have tried

displayword.innerText[3] = “i”           // -----does nothing----

I am confused why the above code using index does nothing, while the below does something

dash.innerText += “i”      //applei

Extra question: Why does the above code using =+ change the formatting of the innerText? I want to keep the large font but it changes to regular font of the element (here I am using h1).

Thank you:)

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You should look at the String documentation, especially String.slice and String.substring

In many languages, Strings can't be modified directly. Instead you "change" it by creating a new string composed of parts of the original.

As for how you'd do it in your case:

var text = displayWord.innerText;
text = text.slice(0, 3) + 'i' + text.slice(4) // apple -> appie
displayWord.innerText = text;

[Edited code slightly]

about 4 years ago · Juan Pablo Isaza Report

0

displayword.innerText = displayword.innerText.replace(oldCharacter, newCharacter);

To replace all occurrences:

displayword.innerText = displayword.innerText.replaceAll(oldCharacter, newCharacter);
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!