Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

add active class to li onclick react

const links = ['link1', 'link2', 'link3'];
const [active, setActive] = useState(null);

<ul>
  {links.map((link) => (
    <li className="nav-item">
      <a 
        href={`#${link}`} 
        className={`nav-link ${active == link && 'm-active'}`}
        onClick={() => setActive(link)}
      >{link}</a>
    </li>
  ))}
</ul>
Comment

add active class to button onclick react


class App extends React.Component {
  constructor(props) {
    super(props);

    this.state = {
      animate: false;
    }

    this.handleClick = this.handleClick.bind(this);
  }

  handleClick(e) {
    // modify the state, this will automatically recall render() below.
    this.setState((prevState) => {
      return { animate: !prevState.animate }
    });
  }

  render() {
    let animationClasses = (this.state.animate ? ' active': '');

    return (
      <div>
        <div className={`vote_card_hover${animationClasses}`}>
          <a>Test</a>
        </div>

        <div>
          <Button title="Toggle Animation" onClick={this.handleClick} />
        </div>
      </div>
    )
  }
}

Comment

add active class to button onclick react

class App extends React.Component {
  constructor(props) {
    super(props);

    this.state = {
      animate: false;
    }

    this.handleClick = this.handleClick.bind(this);
  }

  handleClick(e) {
    // modify the state, this will automatically recall render() below.
    this.setState((prevState) => {
      return { animate: !prevState.animate }
    });
  }

  render() {
    let animationClasses = (this.state.animate ? ' active': '');

    return (
      <div>
        <div className={`vote_card_hover${animationClasses}`}>
          <a>Test</a>
        </div>

        <div>
          <Button title="Toggle Animation" onClick={this.handleClick} />
        </div>
      </div>
    )
  }
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: VueJS - getting the last element of a split string array 
Javascript :: Cannot find module Cannot find module 
Javascript :: rxjs fromevent mouseover 
Javascript :: ProMrRadel2 
Javascript :: Datatable search input with no label - just the placeholder 
Javascript :: udpate next js 
Javascript :: flash effect in react native 
Javascript :: pass image as props vue vuetify 
Javascript :: react native Stack Navigation Prop unused variable 
Javascript :: sending string variable to .net mvc using Ajax JQuery 
Javascript :: window location host vs origin 
Javascript :: how to trigger on Blur only when clicked outside parent component and not child component in react js 
Javascript :: material ui css supports 
Javascript :: check if string is json parsable 
Javascript :: angular input .valueChanges.subscribe value 
Javascript :: pdf extract text nodejs 
Javascript :: whatsapp images not showing in meta tags 
Javascript :: javascript compare two arrays of objects return difference 
Javascript :: supabase realtime connection 
Javascript :: sintaxis map javascript 
Javascript :: get latest journal entry without html 
Javascript :: vuejs bus.emit 2 times 
Javascript :: asp.net mvc with ext js 
Javascript :: // Write a function that takes two numbers (a and b) as argument // Sum a and b // Return the result 
Javascript :: can javascript sort thai value 
Javascript :: $(document).ready(function () { $(".inputs").click(function () { alert($(this).id); }); }); 
Javascript :: public url react for serving django static in production 
Javascript :: Get even numbers with VanillaJS 
Javascript :: convert object to array online javascript 
Javascript :: createTextRange code example 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =