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-mand-button.jtable-edit-mand-button").click(function () {
alert("asdas");
});
});
</script>
</head>
<body>
<h1>My First JavaScript</h1>
<p id="demo">This is a paragraph.</p>
<button class="jtable-mand-button jtable-edit-mand-button" title="Edytuj pozycję">
</body>
</html>
I give you for all of you points for help [closed] thanks
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-mand-button.jtable-edit-mand-button").click(function () {
alert("asdas");
});
});
</script>
</head>
<body>
<h1>My First JavaScript</h1>
<p id="demo">This is a paragraph.</p>
<button class="jtable-mand-button jtable-edit-mand-button" title="Edytuj pozycję">
</body>
</html>
I give you for all of you points for help [closed] thanks
Share Improve this question edited Oct 22, 2012 at 9:56 Rafał Developer asked Oct 22, 2012 at 9:39 Rafał DeveloperRafał Developer 2,05510 gold badges41 silver badges76 bronze badges 2- Two reasons: Wrong selector and not executed at the right time. Please read the tutorial: "As almost everything we do when using jQuery reads or manipulates the document object model (DOM), we need to make sure that we start adding events etc. as soon as the DOM is ready. To do this, we register a ready event for the document.". – Felix Kling Commented Oct 22, 2012 at 9:52
-
Have you included
jQuery
in the page? – saji89 Commented Oct 22, 2012 at 9:55
7 Answers
Reset to default 6- You are trying to use a
$
function (probably from jQuery) without defining it (e.g. by loading jQuery) - You are trying to find the event handler before the element you are binding to has been created
- 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) - You are using a
descendant binator
and atype selector
, but thetype
should be aclass
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) - 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-mand-button.jtable-edit-mand-button").click(function () {
alert("asdas");
});
});
</script>
You have class name, so class selecter starts with .
in jquery.
$(".jtable-mand-button.jtable-edit-mand-button").click(function () {
alert("asdas");
});
you should use . for class and # for id
$(".jtable-mand-button").click(function () {
alert("asdas");
});
$(".jtable-mand-button.jtable-edit-mand-button").click(function () {
alert("asdas");
You need to include the '.
' after .jtable-mand-button
as jtable-edit-mand-button
is a class.
I hope you have jQuery declared? If so, try this:
$(".jtable-mand-button.jtable-edit-mand-button").click(function () {
alert("asdas");
}
As per your code you have used # for call click event function But # is use for ID and dot (.) is used for class so you have used .(dot) instead of #
$(".jtable-mand-button.jtable-edit-mand-button").click(function () {
alert("asdas");
});
Assuming you've downloaded jquery you have to import the js file:
<script type="text/javascript" src="yourPath/jquery-1.7.2.js"></script> //your jquery version
Then you can try as above answers or:
$("button[title='Edytuj pozycję']").click(function(){
alert("asdad");
});