problems with $().click() when generating JavaScript code with a PHP loop
<p>Regards. 
I am generating an .click event for every element of my table using a php loop like this:</p>

<pre><code>&lt;?php foreach ($elements as $element){ ?&gt;
    var element_id = &lt;?= json_encode($element['element_id']));?&gt;;

    $('#'+element_id+'_button').click(function() {
        $('#'+element_id+'_interval').toggle();
        if ($(this).hasClass('active')){
            $(this).removeClass('active');
        }
        else{
            $(this).addClass('active');
        }
    });
    &lt;?php }?&gt;
</code></pre>

<p>the problem is, when <code>$('#'+element_id+'_interval').toggle();</code> the element is not responding but it adds and removes the classes correctly, somebody help me please.</p>
