How to use jQuery to select class name converted by css-loader?

I am using webpack with css loader. Everything works fine, except that I don't know how to use jQuery to select the css-loader class transformed. The converted class name looks something like this: "src-styleauthTextboxLeft1Npf4" with the following css-loader configuration:

css?sourceMap&modules&importLoaders=1&localIdentName=[path][name]__[local]__[hash:base64:5]' 

Here is the reaction code

 const Auth = (props) => { const toggle = (event) => { // Working example $('#container').css('background', 'blue'); // Not working $(styleCSS.container).css('background', 'green'); }; return ( <div id="container" className={styleCSS.container} onClick={toggle} /> ); }; 

Is there a way to make the second option work?

+5
source share
1 answer

If styleCSS.container is a class, you just need to add . in front of him. Try the following:

$('.' + styleCSS.container).css('background', 'green');

+2
source

Source: https://habr.com/ru/post/1260115/


All Articles