showing results for - "change style on click react"
Alan
12 Sep 2020
1Html
2<div id="app"></div>
3
4Css
5button{
6  width: 80px;
7  height: 40px;
8  margin: 15px;
9}
10.blackButton{
11  background-color: black;
12  color: white;
13}
14
15.whiteButton{
16  background-color: white;
17  color: black;
18}
19
20React
21class Test extends React.Component {
22  constructor(){
23         super();
24
25         this.state = {
26              black: true
27         }
28    }
29
30    changeColor(){
31        this.setState({black: !this.state.black})
32    }
33
34    render(){
35        let btn_class = this.state.black ? "blackButton" : "whiteButton";
36
37        return (
38             <div>
39                 <button className={btn_class}
40                         onClick={this.changeColor.bind(this)}>
41                           Button
42                  </button>
43             </div>
44        )
45    }
46}
47
48ReactDOM.render(<Test />, document.querySelector("#app"))
49
queries leading to this page
how to change style property on button onclick in react functionadd style to element react js on clickhow to change style while click in reactclick change css reactchange css with react onclickonclick change style in reactreact apply style onclickreact style element onclick buttonhow to chnage the color of a page when a button has been clicked jsxwhen clicking apply style reacthow to change element style in react on clickreact adding styles on clicckreact js change css onclickreact onclick change css classreact onclick change css directlyhow to change button color onclick react bootstrapadd style to element onclick reactreact change style of element in click handlerreact update style on clickchange styless when element is clicked reactone or the other button is clicked 2c color changes reactreact apply style after event changestyle element when onclick react how to change css on click in reacthow to apply style on click a button reactreact change css class onclickonclick change the background color reactadding style reactjs on clicktrigger inline style on click reactbutton on click change the background in reactonclick button color reactreact change css on click functional componentonclick event change style reactonclick change the css reacthow to change style on click in reactstyle something if clicked reactchange css onclick react functionreactjs set styles on button clickedchange css onclick event reactreact onclick change button coloronclick i want to change the style of an element on reactadd css on button click in reacton click change css reactreact changing styles on clickchange style function onclick react javascriptnext react change style on clickonclick add style reacthow to put button in cheat reactreact change css on clickreact set style on clickreactjs change button color when clickreact change button color on click is satestateonselect change css reactchanging style of body onclick reactchange button style on click reacton click style change reactchange css react onclickreact onclick change cssreact on click add stylechange button on click reactchange style with onclick in reactreact js change style on clickreactnative onclick change stylereact change the style of an element on clickonclick will change the style in reactchange style by onclick in reactjschanging style of page on button click jsxreact changing style on clickbutton react edit the css when you clickchange css in react on clickadd style react onclickstyle with onclick reactchange the color of the button clicked reactjsreact changing style based on click eventstyle onclick change reactreact add css onclickchange div style onclick react functionreact onclick style changereact click button to change colorchanging button color on click in reactchange css properties on click reacthow to change style proprty onclick in react jsreact onclick change css stylechange style on button click reacthow to change css onclick reactjsreact change style on click item react hoock change style on click itemhow to change button color onclick react jschanging react component style with onclickreact onclick apply cssonclick change style on component reacthow to transform a button on click in reactchange back button icon react navigationon form button on click change style reactreact change style on click targetchnage the style of a component on recat onclickreact change css on button clickonclick append style of a div reacton click of function add some style in reactreact on active css changehow to style react components onclireact add css to click on buttonreact change bg with button clickreact change css style onclickreact change link color after clickedreactjs change style on clickreact change style of component on clickchages style o click react codehow to change css on click reacthow to change a css property onclick reactchange jsx dic style on clickreact change css style on clickreact onclick edit csshow to change a button on click in reactchange style react components on clickchange css style with react onclickreact change color on clickchange button color when clicked css reactonclick change element style reactjsonclick react change stylereact change text color onclickreact change style on click typereact change styles on button pressreact change button onclickhow to give style onclick function in reactjsreact set style property onclickchange style of div on click reacthow to add style on react component after clickreact js onclick change css classreact button change divreact change style of element on clickclick event to change the style of elements css reacthow to transform a button on click into a different botton in reactcss onclick function in reactreact change style onclickhow ot changecss on click in reactjsx change style onclickreact on click change cssreact add css to button on clickhow to change to css properties with an onclick in react functional componentset css react on onclickhow to change button color when clicked reactadd style when i click a button reactstyle onclick button reactchange style when click reactchanging the style of component using onclick in reacthow to change the color of button when clicked react jsreact on click change styleset style when clicked element in reactchange style when clicked reactchange button color onclick javascript reactreact button onclick change coloronclick change styles bind style component ractreact native change style of element on clickbutton change color on enter button pres reacthow to change an elements css on click reacthow change background color with button click reactchange style onchange reactonclick change style reactreact add style to component on clickreact onclick button color changechange css on a click in reactchanging css on click reactreact add style on clickadd style on click reactchange border color on click button reactreact set style in click handlerhow to add style on button click in react jshow to change color using onclick button in reactonclick style reactreactjs change button color when clickistyle onclick in reactset style onclick reacthow to change button color on click in reacthow to change style when i click button in reactonclick change color of button in reactchange color button on click reactonclick item css change in react jshow to change a css property on click reactstyle component on click reactreact onclick class css property changehow to change button coclor when clicked reacthow to change style onclick react 5chow to change css in react after clickadd css to a react onclick functionreact change style of button with clickreact change button color on clickonclick change css reacthow to change css class onclick in reactreact chand the style onclickhow to change css property on click in reactadding through style when clicked react jschange button color onclick reactonclick event change css reactchange style onclick react javascripthow to change css style onclick reactchanging style onclick reactadd style onclick reactchange style of another on click reactreact css style on clickchnage style of elemt on lcick react using functionshow to change style onclick function in reactreact change css onclickwhen onclick change color reactchange style on click of an element by id in reactreact apply style on button clickchange buttons on click reactadd css to a react onclickhow to change div style after clicking a button reacthow to change css with onclick reactreactjs change button color when pressedhow to set style through onclick event in reactchange css style onclick reactchange element style on click react jshow to change the background color after clicking the button in reactreact change the style of a dom element on clickreact change style of event targetcss button click reactchange button color onclick of button in reactreact change button style onclickchange css property in react on clickchange css on click reactchange inline style on click reacton click change style reacthow to change button color and text when clicked reacthow to change color of button with different div reactonclick change style reactjsonchange change style reactchange css based on click reacthow to apply css when clicked reacton button clcik change width react jschange button color when clicked reactchange style on click reactbutton react bootstrap onclick color changeonclick event change other elements style reacthow to style with onclick in reactset button style onclick reactchange style of component on click react nativechange style 3d of component on click react nativereact change button style after clickhow to change the button color on click using react on button click change button color reacthow to change the style onchlick in reacthow to styleing onclick in reactbutton color when clicked reacthow to change style onclick in react functional componentreact change style on clickreact onclick add style to existing style classchange style of element react on clickreact change the style buttonhow to change css attributes on click reactset button style on click reactreact get set style on clickchange button style onclick reactjsupon onclick change style in reactchange the style of clicked components only reactchange width of div on click reactchange css style on click reactchange elemt style onclick reactonclick change style css reacthow to change button onclick in react button changes css reactreact onclick stylingonclick css change reactadd style class react onclickchange styling on click reactreact change css attribute onclickreact change button while clikcingreact change styles when click react add style onclick react change style onclick inlinereactjs onclick stylingreact onclick add stylehow to change a style when clicked in reactstyle in onclick function in reactapply css styles when button is clicked reactstyling element onclick reactreact event change styleonclick change button color reactchange div style onclick reactchnage style of elemt on lcick reactbutton change color on click reactadd style onclick react jsxhow to change the backgroud color on clicking a button with reactadd style on button click react jreact js add style in html tag on button click eventcss change color on click toggle reacthow to change css button click reactjschange a button color when clicked react jsreactjs change button color on clickreact onclick change stylechange css class on click react jsstyles add in react js onclickreactjs change css on clickreact click event cssstyles inside onclick in reactreact css button clickchange style on lcikc reactchange button style onclick reactreact js change element style on clickclick style change reactreact add style into onclickadd css on click element reactchange button color on lcik reactjsreact when i click button background color changechange css onclick reactreact change css on nutton clickreact change button color onclickreact change style on button clickapplying styling only to the clicked element reactreactjs change button color when pressing the mousereact add styles to clicked componentadd css to react element on clickchange the style by clicking reactchange button color on click self without state in reactreact change element style on clickchange style of a list in react on button clickreact native onclick change stylechange properties of css on click reactreact update css on clickhow to change css on button click in reactchange button style when clicking reactreact button change color on clickhow change style of buton after onclick reactchange style on onclick eeactonclick change the css react 5dhow to change button style on click react jshow to change to css properties with an onclick in reactreactjs change style content onclickreact onclick set stylehow to set style on click in reactinouonclick change style reactreact add css on click functionchange css on button click reactreact onclick apply stylehow to change css onclick in react jsreact change style on eventchange style on sclick reacthow to change style using event handler in reactonclick e styles reactadd a style on a click event reacthow to change style onclick reactchange button color on active reactchanging color of button on click inside form reactchange all buttons on click reacthow to change style of div in react with onclickhow to add style in when button is click in react jschange style onclick reacthow to change style of div in react with onclick in function componentreact onclick add cssreact change width of element on clickreactjs change button color when clickedchange style of the element when clicked in react functionchange style on click react style componentset css on click reactif button clicked change color reacthow change background color with button click react functionadd style to field in react using button clickhow to change style on event in reactreact change styles on clickreact style sheet on clickevent target change style reactchange component css in handleclick reactreact onclick change button stylehow to change css property in react onclickonclick style change reactchange button color on click reactchange element style react on click4get event react for stylereact change button style on clickhow to change the color of the button on click using reactchange style of another div on click reactreact onclick css changechange style because of event react jschange style onclick react elementhow to change style class by using onclick function in react jschange styles react onclickonclick change css react js change style in click react jsreactjs change color on clickhow to fade state change in reactchange css of button react elementreact js div onclick change colorreact add onclick change functional component stylechange style onclick with syled componentschange css property onclick reacthow to add style in react js by onclick eventshow to change css onclick reactchange color on click reactonchange event change style reactreact onclick styleadd style class react on clickchange style of react element on clickchnage style with click reacthow to change css on click event reactchange css onclick in reactchange style on click react