JSFiddle - React, Tailwind, and code Playground
HTML
<form action="javascript:alert('form')";>
<ul class="stats">
<li id="topic_23"class="score"><h2 class="score_up">12</h2><span style="text-align:center;">Supporters</span></li>
<li>
<button type="submit" value="Actions" class="support" title="support">
<i></i><span>Support</span></button>
</li>
</ul>
</form>
JavaScript
$("form").live("submit", function(e) {
e.preventDefault(); });
$('button.support').live('click', function(e) {
//get the id
var $score = $(this).closest("li").siblings('.score'),
the_id = $(this).closest("li").siblings('.score').attr('id').split('_').pop();
//the main ajax request
$.ajax({
context:this,
type: "POST",
data: "action=support&id=" + the_id,
url: "/echo/json/",
success: function (msg) {
$score.find("h2.score_up").html(the_id).fadeIn();
}
});
});