Message from JavaScript discussions

June 2018

— Hi everyone how to edit text in a lot of div class in html page, to Upercase (using javascript technic)

<div class="desc">a description here</div>

i read about https://www.w3schools.com/jsref/jsref_touppercase.asp

but it use variable. in my case variable is not right, because this div class is more than 50 times. and the text is not same one and other.

my desired result is :

<div class="desc">A description here</div>

Message permanent page

— 

Select all div elements with that class, then use the map method to change the inner text of each element toUpperCase

— Map() is for the array, anyway do you has any example?
how about looping? does javascript support loop for something like this?

Message permanent page

— Selecting elements by array gives you an array

— Selecting by class ie

— Actually a NodeList, but mapping won't help anyway

— You're not transforming elements, you're just mutating them

— .forEach

— Var elements =document.getElementByClass('desc' )
elements.map(element=>element.innerText=element.innerText.toUppercase()

Message permanent page

— Haven't tested this but you can try

— 1. NodeLists don't have .map
2. You're mapping elements to strings now, this would return a list of uppercased strings, which is pointless

Message permanent page

— Juzuz. its hot in here. i have about 40 degrees. questions are.. very simple, ye. never heard about getElementByClass. querySelectorAll i suppose..

Message permanent page