I have a dialog box which get list of students from an ajax call and I am loading the data with .html()
method of jquery.
I put the html data like this into the dialog box.I want to make each student name clickable.When I click first,the background of selected .student_list_div
should be green
. If I click again,I should make it background none
.If clicked again, the color should be green in order to make the user know that it is selected or not.I have done the jquery method also.But its not working properly.
<a href='' class='student_list' id='studentid1'><div class="student_list_div">
StudentName1</div></a>
<a href='' class='student_list' id='studentid2'><div class="student_list_div">
StudentName2</div></a>
and so on.......
My jquery method is like this.
$("#dialog_wrapper").on('click','.student_list',function(){
if($(this).data('clicked'))
{
$(this).find('.student_list_div').css('background-color','none');
}
else
{
$(this).click(function(){
$(this).data('clicked',true);
$(this).find('.student_list_div').css('background-color','green');
});
}
return false;
});
Please help me