Well you could add something like this at the start of the “click” handler:
$(“.reaction-post”).removeClass(“dislike like”);
This will, on a like/dislike button click, remove all “like” or “dislike” class to your .reaction-post, and then your script applies a new one depending on the clicked button.
Note: if you have many elements like this on your page (DOM) (many like and dislike button), you may want to restrict the class manipulation to the clicked element.
Edit: your code could look like this (not tested, but you get the idea):
<script>
$(function(){
$('.reaction-post div').click(function(){
var likable_element = $(this).parent(); //the .reaction-post, easier to manager multiple likeable element on the same page
likable_element.removeClass("dislike like");
var lod = $(this).attr('data-title');
var idr = likable_element.attr('data-id');
localStorage.setItem(idr,lod);
var ratinghis = localStorage.getItem(idr);
likable_element.addClass(ratinghis);
});
});
</script>