简体   繁体   中英

How to solve Uncaught TypeError: Cannot read properties of undefined (reading 'toggle')

I would like to add a "-js-expanded" class to this element if someone hover over a tag. how can I do this?

<a href="" target="_self" class="sticky-cta" onmouseover="myFunction()" >
  <span class="sticky-label">GET STARTED</span>
  <i class="icon-features-productivity"></i>
</a>
  function myFunction () {
      this.classList.toggle("-js-expanded");
  }
  .-js-expanded {
  color: red;
  }

 function myFunction (element) { element.classList.toggle("-js-expanded"); }
 .-js-expanded { color: red; }
 <a href="" target="_self" class="sticky-cta" onmouseover="myFunction(this)" > <span class="sticky-label">GET STARTED</span> <i class="icon-features-productivity"></i> </a>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM