DocGrimwig Posted October 3, 2015 Share Posted October 3, 2015 In the following code: <codeblock> <script> $(document).ready(function(){ $("#hide").click(function(){ $("img").hide(); }); $("#show").click(function(){ $("img").show(); }); }); </script> </codeblock> Is my method and syntax correct for hiding an <img>? Thanks, Doc Link to comment Share on other sites More sharing options...
dsonesuk Posted October 3, 2015 Share Posted October 3, 2015 (edited) Yes! that is correct, to show/hide img instantly without delay, else you colud include time period in millseconds $("img").show(2000); to cause it to slowly expand. although $(document).ready(function(){ ...}); can be done using shorthand $(function(){...}); Also <codeblock>...</codeblock> should be ['code']...['/code'] WITHOUT single quotes Edited October 3, 2015 by dsonesuk 1 Link to comment Share on other sites More sharing options...
dsonesuk Posted October 4, 2015 Share Posted October 4, 2015 You can of course go for a single button 'show/hide‘ and use toggle() https://api.jquery.com/toggle/to cycle between show and hide (which is essentially display: block or inline and then none). 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