Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery click alert()

Do you know why this method click doesn't show alert? Because I'm not able to catch this event.

<!DOCTYPE html>
<html>
<head>
<script src="jquery.js"></script>
<script>
jQuery(function () {
    jQuery(".jtable-command-button.jtable-edit-command-button").click(function () {
        alert("asdas");
    });
});

</script>
</head>
<body>

<h1>My First JavaScript</h1>
<p id="demo">This is a paragraph.</p>

<button class="jtable-command-button jtable-edit-command-button" title="Edytuj pozycję">

</body>
</html> 

I give you for all of you points for help [closed] thanks

like image 571
Rafał Developer Avatar asked Nov 15 '25 10:11

Rafał Developer


2 Answers

  1. You are trying to use a $ function (probably from jQuery) without defining it (e.g. by loading jQuery)
  2. You are trying to find the event handler before the element you are binding to has been created
  3. You are using an id selector but the element doesn't have an id (it does have a class) (Note: after the first edit of the question, this is no longer the case)
  4. You are using a descendant combinator and a type selector, but the type should be a class and the element you are targeting belongs to both classes. It doesn't have an ancestor element which is a member of either of the classes. (Note: The HTML class attribute takes a space separated list of classes)
  5. The end tag and label for the button are missing

A fixed version of the JS part would be:

<script src="jquery.js"></script> <!-- Set this path correctly -->
<script>
jQuery(function () {
    jQuery(".jtable-command-button.jtable-edit-command-button").click(function () {
        alert("asdas");
    });
});
</script>
like image 112
Quentin Avatar answered Nov 18 '25 07:11

Quentin


You have class name, so class selecter starts with . in jquery.

$(".jtable-command-button.jtable-edit-command-button").click(function () {
    alert("asdas");
});
like image 38
Yograj Gupta Avatar answered Nov 18 '25 07:11

Yograj Gupta



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!