javascript - Hidden Divs - Jquery Closing and Efficiency -


i'm trying create multiple divs can closed click of button. being novice @ jquery, i'm sure there better ways this.

my question is: there better ways this?
edit: there way have 1 div open , cancel out , open 1 in case user not close it??

    //hidden divs     $(document).ready(function () {     $(".x").click(function () {     $("#tcm_content").hide();       });     });      $(document).ready(function () {     $(".x").click(function () {     $("#bazinga_content").hide();       });     });      //thumbnails     $("#tcm").click(function () {     $("#tcm_content").show("600", function () {});     });      $("#bazinga").click(function () {     $("#bazinga_content").show("600", function () {});     }); 

here's fiddle: http://jsfiddle.net/0t6uqwlm/13/

you can close multiple divs in click event this

$(document).ready(function () {     $(".x").click(function () {         $("#bazinga_content").hide();         $("#tcm_content").hide();     }); }); 

and dont need use multiple document.ready functions. can use 1 document.ready , put it.

working jsfiddle here https://jsfiddle.net/0t6uqwlm/10/

new jsfiddle update made in question https://jsfiddle.net/0t6uqwlm/12/


Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

order - Notification for user in user account opencart -