CUTCODEDOWN
Minimalist Semantic Markup

Welcome Guest
Please Login or Register

If you have registered but not recieved your activation e-mail in a reasonable amount of time, or have issues with using the registration form, please use our Contact Form for assistance. Include both your username and the e-mail you tried to register with.

Author Topic: appending a classname  (Read 368 times)

durango_d

  • Full Member
  • ***
  • Posts: 124
  • Karma: +1/-0
appending a classname
« on: 31 Oct 2020, 01:14:51 am »
Hi, i want to add a css color class to an already existing classname value, how do i do that..

here is what i have

the childNodes look like this
NodeList(6) [text, h3, text, div, text, button#togglePark.fas.fa-parking]

so i know the child i want is #5


Code: [Select]
console.log(section.childNodes[5]);

// <button type="button" class="fas fa-parking" id="togglePark"></button>

in my css
Code: [Select]
.parkred {
   color: #ff949b;  /* lt red */
}


and here is my code but it tells me that parkred does not exist

Code: [Select]
section.childNodes[5].className += " " + parkred; 

is the syntax wrong?

thanks
Squeeze it Harley! Don't yank it!  It's not your D...!  Squeeze it !

durango_d

  • Full Member
  • ***
  • Posts: 124
  • Karma: +1/-0
Re: appending a classname
« Reply #1 on: 31 Oct 2020, 01:23:42 am »
Ok i think i understand, its trying to tell me that the var parkred is not defined, not the css value.. so all i have to do is let it know that the var parkred = the text "parkred" lol   

Code: [Select]
parkred = "parkred";

this would be better with no new var

Code: [Select]
section.childNodes[5].className="fas fa-parking" + " "+"parkred"; 

Squeeze it Harley! Don't yank it!  It's not your D...!  Squeeze it !

 

SMF spam blocked by CleanTalk

Advertisement