Jump to content

have to click twice on link to run javascript function??


friedice

Recommended Posts

<a href="#" ><img src="img/sign_up_button.png" alt="signup" width="200px" height="40px"/></a>

 

calls this js

 

$(document).ready(function() {
  $('#slideleft a').click(function() {
    var $lefty =  $('div.slideleft > div')
    $lefty.animate({
      left: parseInt($lefty.css('left'),10) == 0 ?
        -$lefty.outerWidth() :
        0
    });


  });

}); 

 

i have to click twice on the link to call that function?

is there a reason why this happens?

Link to comment
Share on other sites

i tried using that but i still require 2 clicks to activate the js script

i thot it would be something to do with the href inside the a tag since it called an empty url from it then calls the js, so i tried using button tag instead and still doesnt work >.<

starting to frustrate me

Link to comment
Share on other sites

The problem may be line var lefty = $('div.slideleft > div'); needing a delimiter?  Anyways, here's a little easier to read code and maybe it will work now?

 

$(document).ready(function()

{

$('#slideleft a').click(function(e)

{

e.preventDefault();

 

var lefty = $('div.slideleft > div');

 

lefty.animate({

left: parseInt(lefty.css('left'), 10) == 0 ? -lefty.outerWidth() : 0

});

 

return false;

});

});

Link to comment
Share on other sites

thanks it works now i forgot to set the left value initially in the css for the second div >.<

You could just check if it's undefined then set it in the function, in case you wish to use this for multiple elements, then you wouldn't have to set them manually.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.