简体   繁体   中英

How can I make font awesome icons clickable with Javascript

Im trying to give this set of font awesome icons to be clickable ( so when I click on them, I get directed to the page I want)

<i class="fas fa-chart-line"></i>

<i class="fas fa-utensils"></i>

<i class="fas fa-newspaper"></i>

<i class="fas fa-user"></i>

<i class="fas fa-sign-out-alt"></i>

How can I accomplish this with Javascript or if there is another way to work around it? I know that you can do this by wrapping the icons with <a href="" , but I'm just looking for another way to do it

onclick Event

https://developer.mozilla.org/en-US/docs/Web/Guide/Events/Event_handlers

Example

<button onclick="myFunction()">Click me</button>

Syntax In HTML:

<element onclick="myScript">

In JavaScript:

object.onclick = function(){myScript};

In JavaScript, using the addEventListener() method:

object.addEventListener("click", myScript);

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