Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

How do I target and change the style of a different element when I click a button in react

class App extends Component {
  constructor() {
    super();
    this.state = { hidden: false };
  }

  handleFinish = () => {
    console.log("CLickedddd");
    this.setState({ hidden: !this.state.hidden });
  };

  render() {
    return (
      <>
        <button id="finish" onClick={this.handleFinish}>
          Finish
        </button>
        <div
          style={{ height: 300, width: 300, backgroundColor: "red" }}
          className={this.state.hidden ? "hidden" : ""}
        ></div>
      </>
    );
  }
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: file path to blob javascript 
Javascript :: Backbone Template Simple Example 
Javascript :: computed properties in react 
Javascript :: adding javascript object within array 
Javascript :: ES6 reactjs problems 
Javascript :: Solution-4--solution options for reverse bits algorithm js 
Javascript :: java script return array 
Javascript :: event 
Javascript :: js onclick add table row 
Javascript :: jquery equivalent of number_format( 
Javascript :: js function to print word starts with vowels of given string 
Javascript :: ampscript remove special character 
Javascript :: router.push 
Javascript :: js return 
Javascript :: jsx attributes 
Javascript :: switch statement javascript 
Javascript :: upload image with react 
Javascript :: Node.js (node 11.12.0) sample 
Javascript :: _.isString 
Javascript :: how to run react app on apache server 
Javascript :: array of numbers to array of objects 
Javascript :: javascript Rename in the module 
Javascript :: javascript AutoCorrection in Date Object 
Javascript :: Save multiple Child 
Javascript :: nodjs : Stream for big file 
Javascript :: mongoose schema index of multiple columns 
Javascript :: vuejs.org español 
Javascript :: phaser animation on start event 
Javascript :: permissions in chrome extension javascript 
Javascript :: javascript 2021 
ADD CONTENT
Topic
Content
Source link
Name
6+4 =