Skip to content
Advertisement

How to do JS functions with PHP echo?

I’m trying to create a popout menu for an array of values that are echoed from the database. On the click of the svg, the popout menu that corresponds with the svg in the echo, needs to be shown. Except so far, it only works for the first one that is echoed. How to I fix it so that it show the popout that corresponds with the correct svg. Here’s what I’ve currently got :

PHP/HTML :

JavaScript

JS :

JavaScript

Advertisement

Answer

If each popout <div> appears immediately after its corresponding <svg> tag (as in your example), you can take advantage of the .nextElementSibling property to get the <div> that follows the <svg> that was clicked.

At the end of your HTML:

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