I wonder how I can add a CSS class to a link based on the ID in the link, with jQuery. I wan't to add the CSS class "active" to the link if the if-statement is true. Not that I dont want to remove "pFavorite" from class in link if the statement is true, I just want to add active to, like this class="pFavorite active" Im not that in to jQuery yet. I hope my code still explains what I want to achieve.
<?php
foreach($statement as $p)
{
if(array_search($p['id'], explode(",", $_COOKIE['cookie'])))
{
?>
<script type="text/javascript">
$("#<?php echo $p['id']; ?>", ".pFavorite").addClass("active");
</script>
<a href="#" class="pFavorite" id="<?php echo $p['id']; ?>">IMG HERE</a>
<?php
}
}
?>
$().ready(function() { /* code here */ });