DNA180 Posted July 26, 2013 Share Posted July 26, 2013 (edited) Hello guys!!! :DI think I need your help here... I have made this JS code below in to my site and I have a problem. When I click on maximize icon, first time doesn't work and it works on second click!!! Does anybody knows what am I doing wrong???FIDDLE EXAMPLE: HERE CODE EXAMPLE: function Images_MaxMin(){ var div_1 = document.getElementById("image_max");var div_2 = document.getElementById("image_min");var big_img = document.getElementById("big_image");var img_url = document.getElementById("img_url"); if (div_1.style.display == 'block' || div_1.style.display == '') {div_1.style.display = 'none'; big_img.src = ''; div_2.style.display = 'block';}else {div_1.style.display = 'block'; big_img.src = img_url.value; div_2.style.display = 'none';}} Thank you in advance!!! Edited July 26, 2013 by DNA180 Link to comment Share on other sites More sharing options...
thescientist Posted July 26, 2013 Share Posted July 26, 2013 one thing I see, is your else conditional is incorrect, you are using assignment instead of testing for equality, like you are doing in the if clause. If you are trying to figure out why your code isn't working, you should learn to debug and check for errors. Open your error console, or add console logging to make sure the elements and variables you are testing/checking against are what you expect them to be, and to log the flow of your code. Link to comment Share on other sites More sharing options...
jeffman Posted July 26, 2013 Share Posted July 26, 2013 The problem is your conditional: if (div_1.style.display == 'block' || div_1.style.display == '') When the page loads, div_1 displays none, so the first test returns false. But style.display IS an empty string, so the second test returns true. Change your conditional. 1 Link to comment Share on other sites More sharing options...
DNA180 Posted July 26, 2013 Author Share Posted July 26, 2013 My friend "Deirdre's Dad" thank you very much for your help!!! You are right... I just removed the second part of IF and it works fine!!! :DMy friend "thescientist" thank you too for your answer!!! 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