У меня есть функция в моем JS-файле, которую я хочу присвоить переменной PHP переменной $ counter. Я получаю сообщение об ошибке: $ counter не определен.
Heres РНР-код:
<?php
$counter = 0;
foreach($res as $category){
echo '<div class="category" onmouseover="doChangeFontWeight($counter);" onmouseout="undoChangeFontWeight($counter);">';
echo '<p class="categoryDescription">'.utf8_encode($category['description']).'</p>';
echo '</div>';
$counter++;
}
?>
Javascript:
function doChangeFontWeight(counter) {
"use strict";
document.getElementsByClassName("categoryDescription")[counter].setAttribute("style", "font-weight: 900");}