Streaming live at 10am (PST)

How do I add javascript or jquery script to a button or text in Webflow

I have created a modal and I want to stop the Youtube video from playing in the background when the modal is closed. How do I add the code to a button or text? If you check on my site, I have a Link Text that I want to add the embedded code too, but it is not working?

You can find this helpful:

I need to do the same, but this article is not helpful at all.
The question is how to attach onClick attribute to link or button.

I would simply add an id to your button within the Webflow UI, then target that button with javascript custom code by adding a “click” event listener which would then run whatever function you like.


<button id="button">button</button>


(function clickMe() {
  const button = document.getElementById("button");
  button.addEventListener("click", event => {
    // 🧠 your onClick script...
    alert("button clicked");

Codepen here

1 Like

It works perfectly. Great thanks, Anthony!

1 Like