Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascrript Wrap all individual words in a span tag based on their first letter

const words = document.querySelector("#words").outerText.split(" ");
const wordsDiv = document.querySelector("#words")

wordsDiv.innerHTML = ""
words.map((el) => {
  wordsDiv.innerHTML += `<span class="${el.substring(0, 1)}">${el}</span> `
})

<div id="words">red green blue orange</div>
 
PREVIOUS NEXT
Tagged: #javascrript #Wrap #individual #words #span #tag #based #letter
ADD COMMENT
Topic
Name
8+4 =