0

Why this doesn't work actually please?

<script>
$('button[type=submit]').not('.disabled').click(function(event) {
   alert('Button Clicked');
});
</script>

<button type="submit" class="btn btn-primary btn-md">Click me</button>

When I click on this button, it should fire the alert.

I also tried this:

$('button[type=submit]:not(.disabled)').click(function(event) {
0

2 Answers 2

1

The snippet below works. The reason it doesn't work is probably because you don't have jQuery included. Add <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> to your code and it should work.

$('button[type=submit]').not('.disabled').click(function(event) {
  alert('Button Clicked');
});
<button type="submit" class="btn btn-primary btn-md">Click me</button>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

Sign up to request clarification or add additional context in comments.

1 Comment

Also, it wont work if the jQuery comes before the HTML, unless you wait for the document to be ready: like this. Or move the script below the HTML, like this.
0

You can use onclick() function instead of class.

function btnClick(){
  alert('Button Clicked.');
}
<button type="submit" onclick="btnClick();" class="btn btn-primary btn-md">Click me</button>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.