I am running jQuery script in foreach loop to add classes in html dynamically.I want to add two different classes on different event status but it adds both the class, the class in the if condition and class in else condition.
Here is my code
<?php foreach( $events as $event ){
if ($event->status=='new'){ ?>
jQuery( ".upcoming-events" ).addClass( "new_event" );
<?php }
else {
?>
jQuery( ".upcoming-events" ).addClass( "old_event" );
<?php } } ?>
but it adds both the classes in upcoming-events div.
any hint???
$eventsarray has at least one new and one old element.