HTML make text clickable without making it a hyperlink

For semantics I’d use a <button> element like this:

<button class="link">Clicky</button>

to make the button look like normal text you can use CSS:

button.link { background:none; border:none; }

and for easiness of handing click I’d use jQuery like so:

$(".link").on("click", function(e) {
    // e is the event object
    // this is the button element
    // do stuff with them
});

Although if you have an ID attribute on the button you can use plain JS like this:

var button = document.getElementById("your-button-id");
button.addEventListener("click", function(e) {
    // e is the event object
    // e.target is the button element
    // do stuff with them
});

Leave a Comment