Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make <div>, <li> clickable without <a> tag

Tags:

html

jquery

css

I want a <div> or <li> tag to be clickable (the pointer should change to hand). How can I do it without <a> tag?

Because, when a div is clicked, my javascript loads a text file.

like image 587
Emmet B Avatar asked Jan 17 '26 08:01

Emmet B


2 Answers

You should add style="cursor:pointer" for the hand pointer and onclick="window.location='somewhere'".

<div style="cursor:pointer" onclick="window.location='index.html'">My Link</div>
like image 137
MIIB Avatar answered Jan 20 '26 00:01

MIIB


var myel = document.querySelector('#myel'); // your element

myel.addEventListener('click', function() {
  // do stuff
});

In CSS:

#myel { cursor: pointer }
like image 30
elclanrs Avatar answered Jan 20 '26 00:01

elclanrs