How to dynamically change the name of an element?
The site template generates several blocks using the code:
echo '& lt; ul id = "menu" & gt;';
as a result, several blocks with the same ID are formed on the page.
How to dynamically substitute a prefix for this ID so that each subsequent block on the page is formed with the ID:
etc., as this code is called?
And if not in a loop, then like this:
$menuId = 0; // Где-то в области видимости объявляем переменную.
// Потом просто
echo '<ul id="menu_'.++$menuId.'">';
In general, it is better to write HTML and PHP separately. I mean, don't write all HTML in templates in PHP strings.William House
If blocks are formed in a loop, then you can add the iteration number to the ID by simple concatenationAnonymous
To place the code, please use CodePen or similar tool. Thanks you!