score:4
Accepted answer
try this
function App() {
const [color,setColor]=useState('red');
const [textColor,setTextColor]=useState('white');
return (
<div className="App">
<button style={{background:color,color:textColor}} className='btn btn-primary' onClick={()=>{setColor("black");setTextColor('red')}}>Click here</button>
</div>
);
}
export default App;
OR check link : https://stackblitz.com/edit/react-x7mevv
score:0
App.js
function App() {
const [toggle,setToggle] = React.useState(false);
const toggleIt =()=>{
setToggle(!toggle)
}
return (
<div className="App">
<button onClick={toggleIt}>{toggle?'Hide':'Show'}</button>
<div className={toggle&&'body-color'}>
Body
</div>
</div>
);
}
class in App.css
.body-color{
background: coral;
height:100vh;
}
Source: stackoverflow.com
Related Query
- how to change background color when I click the button using react hooks
- How to change button background color when I click the button in React using Hooks
- How to change the background and text color within button using button onClick in React JS
- Use click handler to change color of button when there are multiple buttons using the same function
- How to change background color of button using react
- how to change the background color of a button without affecting the other buttons in React JS
- How Do I make my Nav Menu option change color or background when I click on it using Javascript only?
- How to change the default screen background color of all the pages in React JS(Next JS) using tailwind CSS
- How do I target and change the style of a different element when I click a button in react
- How to change the background color of th on click in react js?
- How to hide a button when I click the button in react using functional components
- How to change button color when pressed in React Native using TouchableHighlight?
- How to change the menu item's color of sidebar when we click on it with css in React pls
- When I click the button, I want to change the page background color to another color, not black, how can I do it?
- How to Reset a form When I click submit Button I React using React hooks
- how do you single select change the value when the radio button is checked, using react hooks?
- How to change the style of a button when it is clicked in react using css?
- How to click a button into a list array items only effect the related item using React hooks
- How to change background color of react native button
- How to change the color of a active button only in react native
- randomly change the background color of a react app by a click
- How to change the selected table row background color with React
- How to change the selected table row background using Material-UI on React
- How to make one table record editable on button click in React when the table record is mapped?
- React - How to change code written in the old way when using a new approach?
- how to change the font color, font size, and button color in React
- How to add a tab dynamically when we click a button using React js and Bootsrap 4
- How to get the time in seconds after click on submit button using React Count Down Timer
- How to change navbar background color in react when I scroll
- How to change the state value using a click button
More Query from same tag
- Are variables destructured from useState unusable above a return statement?
- Enable a Storybook control conditionally
- Programmatic access to history (history.push etc) in react-router v5 outside of components
- How to update Socket.io handlers without re-connecting in React
- Using Socket.io with typescript and react
- How to change Color of the arrow down textfield material ui
- update the state in React JS array using useSatate
- React-Leaflet offline storage of tiles
- Rendering redirect component based on ajax request
- How to Delete Image from Firebase cloud Storage - REACT
- Is there a way to hide scrollbar in Material UI Table sticky header?
- my image is not showing it's only showing the link on react table
- React jest snapshot only returning empty DocumentFragment
- How can we skip a record while looping through an array in ReactJS
- useState for an object in React
- Integrating Drift chat service within a Gatsby site
- How do I use spread operator in useEffect without infinite loop?
- React Redux Toolkit access value inside array of objects
- I am trying to update a property of an array of object but it is showing Cannot assign to read only property 'isSelected' of object
- Is there an efficient way to make this code DRY?
- Handling state and passing to a component / react.js
- how to compare date and time in javascript using moment
- Set image as object in ReactJS
- How to declare type in this kind of situation?
- React-Router Switch component not rendering components with same path
- Why my code is not showing the answer when i click button "Show Answer"
- Not able to send an axios post to a node js server - net::ERR_CONNECTION_REFUSED on localhost
- Proxy error: Could not proxy request /api/house-listing from localhost:3000 to http://localhost:5000? (ECONNRESET), MERN
- How to update atoms (state) in Recoil.js outside components ? (React)
- Apollo Client useLazyQuery not starting