PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, October 15, 2022

[FIXED] how to get class in javascript with colon syntax for making dynamic class like tailwind css

 October 15, 2022     css, dom, html, javascript, tailwind-css     No comments   

Issue

i want to make dynamic class for hover , focus ,check and others. but I can't able to get those class format(hover:bg-sky-700) for using colon(:).it shows error in console. please provide an idea to make dynamic class like tailwinds. thank you.

<div class="single-bg bg_amber_5 hover:bg_green"></div>

enter image description here


Solution

If your class name contains reserved characters(., :, # etc.) you need to escape it to avoid ambiguity using CSS.escape:

// be careful you don't want to escape the leading "." since it meant to be indicating a class selector
const element = document.querySelector(`.${CSS.escape('hover:bg_green')}`);
console.log(element);
<div class="single-bg bg_amber_5 hover:bg_green"></div>



Answered By - Hao Wu
Answer Checked By - David Marino (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing