Newbie2772 Posted April 1, 2015 Share Posted April 1, 2015 (edited) 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 April 1, 2015 by Newbie2772 Link to comment Share on other sites More sharing options...
justsomeguy Posted April 1, 2015 Share Posted April 1, 2015 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. Link to comment Share on other sites More sharing options...
Newbie2772 Posted April 1, 2015 Author Share Posted April 1, 2015 That is an incredibly useful tool! I figured that part out now I'm going to figure out how to make them continue to disappear rather than reappear upon second click! Link to comment Share on other sites More sharing options...
dsonesuk Posted April 2, 2015 Share Posted April 2, 2015 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. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now