Does jQuery event not fire until second click?

I have the following jQuery code. The first time I click the link, nothing happens; however, when you click the link a second time, the expected action is expected.

$("a[rel]").bind("click", function(){ $(".close_button_change_password").attr('id','change_password_'+$(this).attr('id')); $(this).overlay({ // disable this for modal dialog-type of overlays closeOnClick: true, mask: { color: '#fff', loadSpeed: 200, opacity: 0.8 } }); }); 

Here is my HTML:

 <a href="#" rel="#change_password" id="1">change password</a> 

Does anyone know how I can solve this problem? Thanks in advance for any help.

+4
source share
4 answers

Try

 $("a[rel]").live("click", function(){ .... 

or you could try .. but I don’t think that would solve it.

 $("a[rel]").live("change", function(){ .... 

And make sure it is ready in the DOM.


You can try to prevent the default action, perhaps this interferes with your first click.
 $("a[rel]").bind("click", function(event){ event.preventDefault(); // <---------^^ $(".close_button_change_password").attr('id','change_password_'+$(this).attr('id')); $(this).overlay({ // disable this for modal dialog-type of overlays closeOnClick: true, mask: { color: '#fff', loadSpeed: 200, opacity: 0.8 } }); }); 
+2
source

First of all, paste your code with the $ (document) .ready ({}) operator. This ensures that your dom will only be affected by code after parsing the html syntax by the browser.

0
source

Try

 $("a[rel]").click(function(){alert($(this).attr("id"));}); 

to see that something is wrong with your HTML code. then you can add another statement to debug js code

0
source

From: http://flowplayer.org/tools/overlay/index.html

// select one or more elements to be overlay triggers

Setting the overlay on the HTML click attribute may be redundant. Based on the foregoing, I would suggest that the overlay is already activated when pressed.

0
source

All Articles