0

JavaScript need help for BUTTONS

OK, so i made this code and i cant seem to understand something. When i open a button lets say "button1" and if i want to open lets say "button2" i have to click one time on a button to close it and then click again to open another one. Now i wonder is there a way to make "button2" or "button3" to open in one click after one is already opend but then if i want to close the button (button1, 2 or 3) and show the original paragraph wich is "<p> id="t1"The German The is a bit different<\p>" on second click on a same button that is currently opend. (Значи когато отворя бутон1, за да отвора бутон2 или 3 трябва да кликна два пъти върху него. Въпросът ми е. Как да го направя така че когато се натисне различен от отворения бутон да се смени контента с един клик, но когато кликна върху вече отворения бутон да се затвори и съответно да се покаже "<p> id="t1"The Germ.......<\p>"? Всякаква помощ ще е от полза. https://code.sololearn.com/WRs43gPepNty/#html

10th Jan 2018, 2:09 PM
BG Simeon Simeonov
BG Simeon Simeonov - avatar
1 Odpowiedź
+ 2
You should store the previously clicked button in a variable and if the currently clicked button is NOT equal to the previous button - you clicked on another button. Add the variable prevFn At the end of every button function, set prevFn to the function. Change the open condition: Instead of if (open) Use: if (open && (prevFn == [ insert current function here ])) This means you are already open and this is the one you opened.
11th Jan 2018, 8:41 AM
Lil Taco
Lil Taco - avatar