Skip to content
Advertisement

Dropdown content not showing correctly on button click – dynamically

I have a issue with dropdown content on side http://www.filmwatch.sk/serialy/the-godfather/ When I click on button 1.seria show dropdown content 1.epizode, but when I click on button 2.seria show same dropdown content 1.epizode, but I need show 2 and 3 epizode (dropdown content Godfather S02E02 and Godfather S02E03). Here is code:

JavaScript

Any help is much appreciated

Advertisement

Answer

There are two main problems:

  1. The dropDown boxes all have the same id so the first one is always found in myFunction. An id must be unique in the DOM.

  2. myFunction does not unshow any dropDown that might already be showing

A solution is to remove the use of ids altogether and to get myFunction to clear any currently showing dropDowns.

Replace these two lines

JavaScript

with these

JavaScript

and replace the JavaScript with this

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement