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

127
Views
Adding text at the start of a p element

Let's say I have this paragraph:

<p id="paragraph">Hello World!</p>

I want to add "Hello StackOverflow! " at the start of the paragraph.

document.getElementById("paragraph").innerHTML += "Hello StackOverflow! "

Adding the above line didn't work as it adds the content to the end of the paragraph, not the start.

Is there a way to do this?

Thanks!

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

0

You can use a template string to easily do this:

document.getElementById("paragraph").innerHTML = `Hello StackOverflow! ${document.getElementById("paragraph").innerHTML}`
<p id="paragraph">Hello World!</p>

about 4 years ago · Juan Pablo Isaza Report

0

You can save the previews text in a variable and then update the innerHTML

const el = document.getElementById('paragraph')
const prevTxt = el.innerHTML

el.innerHTML = 'Hello StackOverflow! ' + prevTxt
<p id="paragraph">Hello World!</p>

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!