Search
 
SCRIPT & CODE EXAMPLE
 

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>
Comment

PREVIOUS NEXT
Code Example
Javascript :: Javascript shows me TypeError saying my variable is undefined 
Javascript :: javascript Scroll into a div that is hidden initially in react 
Javascript :: hide navbar and footer on certain pages like dashboard. react-router 
Javascript :: dependent drop down list in jquery 
Javascript :: getting xml from response, make sure server returns valid xml and the "content-type" header is set 
Javascript :: Randomly getting error 500 in Azure App Service when downloading angularjs template 
Javascript :: Changing the value of a dropdown when the value of a number box changes in AngularJS 
Javascript :: angularjs How to render either a number or a HTML element depending on what a function returns 
Javascript :: Angularjs $on called twice 
Javascript :: Angularjs - Deep Orderby - How to handle multiple layers of sorting 
Javascript :: How to hide div based on select the dropdown in angular js 
Javascript :: Conditional navigation inside Tabs 
Javascript :: npx create-create-app movie-app 
Javascript :: How to use search/filter for HTML Divs generated from JSON data using JavaScript 
Javascript :: reverse array without using another array 
Javascript :: sending api with limited fields in express 
Javascript :: disconnect google colab runtime 
Javascript :: morgan tiny 
Javascript :: Variables In Self Invoking Function 
Javascript :: Sending An AJAX Request Using Ky 
Javascript :: phaser change scene 
Javascript :: yoptascript 
Javascript :: datatables data in one line 
Javascript :: what does the text before an object stand for in js 
Javascript :: cubing timer 
Javascript :: javascript call function change last default value 
Javascript :: react native webview get query params 
Javascript :: javascript protect object with proxy 
Javascript :: get the first recurring character javascript 
Javascript :: clear an array 
ADD CONTENT
Topic
Content
Source link
Name
4+9 =