I want to add the ability to have the option to click on certain HTML text and have the correct JavaScript code be executed.
How can I do this?
To make a hyperlink in an HTML page, use the <a> and </a> tags, which are the tags used to define the links. The <a> tag indicates where the hyperlink starts and the </a> tag indicates where it ends. Whatever text gets added inside these tags, will work as a hyperlink. Add the URL for the link in the <a href=” ”>.
In order to disable a HTML Anchor Link (HyperLink), the value of its HREF attribute is copied to the REL attribute and the value of HREF attribute is set to an empty JavaScript function. This makes the HTML Anchor Link (HyperLink) disabled i.e. non-clickable.
Create a hyperlink to a location on the webSelect the text or picture that you want to display as a hyperlink. Press Ctrl+K. You can also right-click the text or picture and click Link on the shortcut menu. In the Insert Hyperlink box, type or paste your link in the Address box.
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 });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With