I have list in foreach loop in Php as like below
<?php
$cnt=1;
foreach ($this->session->userdata('questions') as $row) {
$i=1;
foreach($row as $q) { ?>
<li id="<?php echo "number-". $q->subjectid."_".$i;?>" onclick="showQuestion('<?php echo "#".$q->subjectid."_".$i;?>');" class="btn bg-primary numbers z-answered" >
<?php echo $cnt++;?>
</li>
<?php
$i++;
}
}
?>
It will show question numbers from 1 to 100 (assume)
I want When a user will click any question, It will add demo css class to current question How to achieve it.
You can use jQuery for the purpose if you want to:
$(document).ready(function(){
$('li').click(function(){
$(this).addClass('demo');
//code to remove class from rest of the <li>'s
$(this).siblings().removeClass('demo');
});
});
You can use jQuery's addClass()
method.