[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 478
  • Last Modified:

click is not defined : $('.button').bind(click, alertMe);

Hi

I get the above error for the code below. Can someone please advise:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
            <title>Jquery test</title>
            <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
            <script type="text/javascript">
            $('document').ready(function() {
                  $('.button').bind(click, alertMe);
                  function alertMe() {
                        alert('hello');
                  }
            });
                  
                  
            
            </script>
            
      </head>
<body>
            <button type="button" class="button">click me</button>
</body>
</html>
0
jecommera
Asked:
jecommera
1 Solution
 
mrh14852Commented:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <title>Jquery test</title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $('.button').bind('click', alertMe);
            function alertMe () {
                alert('hello');
            }
        });


    </script>

</head>
<body>
<button type="button" class="button">click me</button>
</body>
</html> 

Open in new window

0
 
Chris StanyonCommented:
The event name (click) needs to be enclosed in quotes:

$('.button').bind('click', alertMe);

An alternative, shortcut is:

$('.button').click(function() {
     alert("Hello");
}
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now