search

Home  >  Q&A  >  body text

Apply styles to variables in template literals in JavaScript

make ${text}bold

I'm trying to apply styles to TEXT inside the backtick operator.

P粉063039990P粉063039990265 days ago400

reply all(1)I'll reply

  • P粉296080076

    P粉2960800762024-04-01 09:13:46

    Insert style in backticks

    const content = document.getElementById('content')
    var text = 'text'
    content.innerHTML = `make ${text} bold`

    reply
    0
  • Cancelreply