dawn
dawn

Reputation: 21

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

Upvotes: 1

Views: 1041

Answers (1)

br41nst0rm
br41nst0rm

Reputation: 31

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);

Upvotes: 1

Related Questions