Simple Machines Community Forum

General Community => Scripting Help => Topic started by: Wellwisher on July 01, 2017, 08:06:37 PM

Title: Javascript: document.querySelector / querySelectorAll issue
Post by: Wellwisher on July 01, 2017, 08:06:37 PM
Hello

Re: Menu dropdown/ Javascript: document.querySelector / querySelectorAll issue

I made a simple jsfiddle to showcase the issue. Basically "option 2" is not triggering:

https://jsfiddle.net/5wg9fzq8/

The .JS code is from CodePen (http://codepen.io/ok2ju/pen/MwyvWY) by author Alexey Vakulich. I am trying to implement 2x drop down menus in 2x locations on a single page in SMF. I have escaped all the apostrophes but only one of the menus work.

I know the issue relates to using 'document.querySelector' which you can only use once but if you use 'querySelectorAll', this can be used multiple times. I have tried many code variations but I am nowhere close. Hoping someone here can shed some light on the javascript snippet or at least point me in the right direction.