Hi all, I am new here and I am working on project for school. I want to create a button and when you press it, it will run this JS such that a div will appear. I am using this so that when you press on a button in my navigation bar, a div will appear below, similar to the iOS folder effect. This is so that the info in the div will not be visible when you first load the page, without pressing the button. However, my project does not really include javascript and I understand learning javascript is very difficult, which I simply do not have time for. Thus I have found a tutorial online which creates this effect, exactly what I want.
The code works flawlessly, and I enjoy the effect very much. However, the button which I press only acts as one function, so that when it opens, I must click a button and when I close it, I must click another button which I do not want. Since I am trash in javascript I cannot figure out how to do so.
Here is the javascript code which allows the effect:
I've been looking at this code for a long time and I can't figure it out. I tried thinking about the if and else tags, however I don't know how to correctly place and code it for it to work.
If you need any other codes please reply, I desperately need help.
You’re on the right track with conditionals (if/else statements (not “tags”)) already. Here is a thought-provoking impulse:
Assign a specific class to the div when it’s open and check for its presence on click of the button. If it is present, you know that the div is open and you have to close it.
Something like:
Code:
open-button -> click:
if(div has class) {
execute functions to close div and remove the class
}
else {
execute functions to open div and add class
}
And by the way: in jQuery you can chain functions; and also, a simpler way to write css('display','block'); is just show(). If you wanna get more fancy you can use fadeIn() (and fadeOut(), of course).