1

Probably something simple so sorry!

Currently, I have <button id="pin">Get pin</button> and it works. (there is a script later on that this calls).

But, I want it to work on some text - preferable an <a href> as the styles are set up on this - so something like <a href="pin">Get pin</a> - obviously this would not work so would like to know how to get it to work! :)

I am trying to get it to run the below when clicking it:

<script>
    $("#pin").click(function() {
        swal("Your support pin", "Your support pin is: {$support_pin}", "info")
    });
</script>

Thanks

Tom Wilson
  • 31
  • 3
  • Note that HTML in your question will be interpreted by our browsers *as HTML*, so you need to escape it as code by surrounding each HTML tag with backticks. –  Jan 07 '20 at 20:56
  • Question needs some code to clarify what you're trying to do. – Matt Jan 07 '20 at 20:56
  • You can set up a click handler on a link as well, not just on a button. – Bergi Jan 07 '20 at 20:57
  • It will work just fine -- though you'll need to prevent the default click handler with `e.preventDefault()`, `return false`, or similar. – Obsidian Age Jan 07 '20 at 20:57
  • I am trying to get it to do this: `` – Tom Wilson Jan 07 '20 at 20:58
  • Does this answer your question? [How to use a link to call JavaScript?](https://stackoverflow.com/questions/688196/how-to-use-a-link-to-call-javascript) – Obsidian Age Jan 07 '20 at 20:59
  • Someone blocked this question. So I have to comment answer. Get pin In your script will be like this; $("#pin").click(function(e) { e.preventDefault(); swal("Your support pin", "Your support pin is: {$support_pin}", "info") }) – glinda93 Jan 07 '20 at 21:01
  • @bravemaster - not working either. I have put this: `
  • Get pin
  • ` `` – Tom Wilson Jan 07 '20 at 21:04
  • Transform this question into chat. Then I'll help you solve that problem. – glinda93 Jan 07 '20 at 21:08
  • How do I do that @bravemaster? – Tom Wilson Jan 07 '20 at 21:09
  • Sorry, you don't have enough reputation. I'll upvote this question so that your reputation is over 20. Then you can join the chat room in this site. Or, this question has already too many comments so you will see the option here. – glinda93 Jan 07 '20 at 21:12
  • I'm not seeing the option for a chat. @bravemaster – Tom Wilson Jan 07 '20 at 21:15
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/205557/discussion-between-tom-wilson-and-bravemaster). – Tom Wilson Jan 07 '20 at 21:17
  • @bravemaster here now – Tom Wilson Jan 08 '20 at 09:50