javascript - Bootstrap Voting button not working -
i have voting system in page, used normal css button, working well. when apply in bootstrap button, not work.
i want used in bootstrap.
normal css button:
<div class="voting_kochi" id="1012"> <div class="voting_btn"><div class="up_button"> </div><span class="up_votes">0</span></div> <div class="voting_btn"><div class="down_button"> </div><span class="down_votes">0</span></div> </div>
convert bootstrap:
<div class="voting_kochi" id="1012"> <div class="voting_btn"><div class="btn btn-default btn-responsive up_button"><span class="glyphicon glyphicon-thumbs-up"></span></div><span class="badge btn-responsive up_votes">0</span></div> <div class="voting_btn"><div class="btn btn-default btn-responsive down_button"><span class="glyphicon glyphicon-thumbs-down"></span></div><span class="badge btn-responsive down_votes">0</span></div> </div>
script:
$(document).ready(function() { $.each( $('.voting_kochi'), function(){ var unique_id = $(this).attr("id"); post_data = {'unique_id':unique_id, 'vote':'fetch'}; $.post('../vote_process.php', post_data, function(response) { $('#'+unique_id+' .up_votes').text(response.vote_up); $('#'+unique_id+' .down_votes').text(response.vote_down); },'json'); }); $(".voting_kochi .voting_btn").click(function (e) { var clicked_button = $(this).children().attr('class'); var unique_id = $(this).parent().attr("id"); if(clicked_button==='down_button') //user disliked content { post_data = {'unique_id':unique_id, 'vote':'down'}; $.post('../vote_process.php', post_data, function(data) { $('#'+unique_id+' .down_votes').text(data); }).fail(function(err) { alert(err.statustext); }); } else if(clicked_button==='up_button') //user liked content { post_data = {'unique_id':unique_id, 'vote':'up'}; $.post('../vote_process.php', post_data, function(data) { $('#'+unique_id+' .up_votes').text(data); }).fail(function(err) { alert(err.statustext); }); } }); });
use hasclass().try one
$(".voting_kochi .voting_btn").click(function (e) { var clicked_button = $(this).children(); var unique_id = $(this).parent().attr("id"); if($(clicked_button).hasclass('down_button')) //user disliked content { post_data = {'unique_id':unique_id, 'vote':'down'}; $.post('../vote_process.php', post_data, function(data) { $('#'+unique_id+' .down_votes').text(data); }).fail(function(err) { alert(err.statustext); }); } else if($(clicked_button).hasclass('up_button')) //user liked content { post_data = {'unique_id':unique_id, 'vote':'up'}; $.post('../vote_process.php', post_data, function(data) { $('#'+unique_id+' .up_votes').text(data); }).fail(function(err) { alert(err.statustext); }); } });
Comments
Post a Comment