Jump to content
Newbie2772

Jquery Animation Need Help

Recommended Posts

Hi guys,

 

So I set up a few boxes on a page and want a random one to disappear whenever any box is clicked on. I am a little rusty and was never that good at coding so this is just for fun/practice.

 

My divs are set up as having id's square(1-18)

 

My jquery code is:

$(document).ready(function() {   $("div").mouseenter(function() {       $(this).animate({           height: '+=50px',           width: '+=50px',           fontSize: '+=100px'});   });   $("div").mouseleave(function() {       $(this).animate({           height: '-=50px',           width: '-=50px',           fontSize: '-=100px'       });    });   var num = math.floor(math.random() * 18) + 1;   var n = num.toString();   var sEvent = "'" + "#" + "square" + n +"'";   $("div").click(function() {       $(sEvent).toggle(400);   }); });

the first 2 sections work fine but I cant get my click function to work properly. Please let me know your thoughts!

Edited by Newbie2772

Share this post


Link to post
Share on other sites

Check your browser's developer console, you should see some error messages. See if you can figure out what they mean first, or else I'll help you.

Share this post


Link to post
Share on other sites

I should think you don't need to include single quotes, or num.toString()"'" + "#" + "square" + n +"'"Just"#square" + num Would suffice, as it would be read as text string anyway.

Share this post


Link to post
Share on other sites

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.   Paste as plain text instead

  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.

Loading...

×
×
  • Create New...