I figured I would just add an answer: Working Fiddle
Javascript:
I wrapped the entire logic in a document.ready to make sure the DOM is fully loaded, which I assume you are doing also.
I also used 'on' instead of 'bind' since that is the jQuery preferred method with their current library.
My ajax call is a mock ajax call for jsFiddle, but you can just replace the url with your index.php.
In the success i used $('.'+vote_id) because you are get the 'class' of the parent, so you need a '.' instead of a '#' in the jquery selector. If I were you i would change the variable 'vote_id' to be called 'parentVoteClass'.
Finally, i used 'append' because you did not want to lose the existing html in the parent tag. This will add the value from result to the end of the existing html in the parent element. If you use prepend(result) it will put it first and using .html(result) will replace it.
$(document).ready(function() {
$('.like').on('click', function(){
var vote_teacher = 1;
var voteclass = 2;
var vote_id = $(this).parent().attr("class");
var poststr="voteclass="+voteclass+"&voteteacher="+vote_teacher;
$.ajax({
type: "POST",
url: "/echo/json/",
data: poststr,
cache: false,
success: function(result) {
var someDatafromResult = "my stuff";
$('.'+vote_id).append(someDatafromResult);
}
});
});
});
HTML:
<div id="parent" class="parentClass">
<a href="#" class="like">Vote!</a>
</div>
UPDATE:
I modified your fiddle: Modified Fiddle
The major change is here:
function main(){
$('#something').on('click','.agree', function(){...code hidden...}
this allows you to bind the event on the parent element, instead of '#something' you could use document as well. Now, if you html with the 'agree' class gets replaced or blown out, the even still lives on.
I faked the successful php return here:
success:function(result){
$('#'+des_id+'').html('<li>text <span class="votes_type "> <a href="#!" class="agree">'+voteNumber+'<img src="png"></a> <a href="#!" class="disagree">disagreenumber<img src="png"></a> </span> </li> ');
;}
I used some inline stringed html to fake an html return result and then used the variable 'voteNumber' which gets incremented with each click to show that it does indeed change and continue to work.