jQuery selector triggering two suplicate events???

HTML, CSS and anything else that deals with client side capabilities.

Moderator: General Moderators

Post Reply
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

jQuery selector triggering two suplicate events???

Post by alex.barylski »

I have the following code:

Code: Select all

<!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" xml:lang="en" lang="en">  <head>    <base href="http://www.somedomain.com/" />    <title>This is the document title</title>                   <script type="text/javascript" src="jquery.js"></script>      </head>    <body>    <script type="text/javascript">   //<![CDATA[  if(typeof jQuery != 'undefined'){    $(document).ready(function()    {      $("#frm_0a7df113baa1138c0c06e9d087cd9e56_0, .btn_cancel").click(function()      {          var ret = confirm("Are you sure you want to cancel and return to the previous screen?");          if(ret){              location.href("/");          }      });    });  }  //]]></script> <form id="frm_0a7df113baa1138c0c06e9d087cd9e56_0" action="/auth/login2" method="post" enctype="text/html">  <div>    <!-- Enter INPUT fields here -->  </div>   <div>    <button type="submit">OK</button>     <script type="text/javascript">      document.write('<button class="btn_cancel">Cancel</button>');    </script>     <noscript>      <div class="note">        <a href="/">Click here to return to the previous screen</a>      </div>    </noscript>  </div></form  </body></html>
When I click the cancel button, I am prompted twice to actually cancel or continue, WTF?

Anyone know whats going on here?

Cheers,
Alex
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: jQuery selector triggering two suplicate events???

Post by Christopher »

You are selecting events from both an ID and a Class. Just do one, or use one of the methods that stop event bubbling/propigation.
(#10850)
Post Reply