Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

189
Views
How to execute JavaScript code when click Button in Webflow

I am newbie in Webflow, In Webflow project I want to get button by id and execute some Javascript code when I click this button.

The code I write:

<script>
    document.addEventListener('DOMContentLoaded', () => {
       let btn = document.getElementById('myButtonId');
       btn.addEventListener('click', () => {
           // handle the click event
           console.log('clicked');
           alert("Hello");
       });
    });
</script>
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You'll either need to move the code to the Page Footer,

or wrap the code in the Webflow's recommended "Webflow ready function":

var Webflow = Webflow || {};
Webflow.push(function() {

    // Your code goes here
    document.addEventListener('DOMContentLoaded', () => {
       let btn = document.getElementById('myButtonId');
       btn.addEventListener('click', () => {
          ...
       });
    });

}); // End Webflow ready function
about 4 years ago · Juan Pablo Isaza Report

0

Java script you can call the function any name you want

 <script>
            function yourFunctionName() {
            alert("hello")
            };
        
        </script>

HTML

<body>
    <button id="myButtonId" onclick="yourFunctionName ()">click here</button>
 
</body>
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!