Languages

jQuery - how to add on click event to button?

14 points
Asked by:
Root-ssh
6593

I have simple html button and I would like to add on click event to this button.
When someone clicks on this button I would like to show alert.
I don't want to use plain JavaScript, I would like to achieve it with jQuery.

My button looks like this:

// ONLINE-RUNNER:browser;

<!doctype html>
<html>
<head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script>
</head>
<body>
<script>
    // code to add on click to button
</script>
<button id="button-id">My button</button>
</body>
</html>

I would like to get element by id and attach click event with jQuery.

0 answers
Hey 👋
Would you like to know what we do?
  • Dirask is a friendly IT community for learners, professionals and hobbyists to share their knowledge and help each other in extraordinary easy way.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.