Hi everyone,
I have a little script just to add or remove a class. When the class have to bee added there is no problem, but when it has to remove it the following mistake is shown:
TypeError: d.removeClass is not a function
I don’t understand why. My JS code is the following:
<script>
function myFunction(respuesta_id) {
let heart;
var id_respuesta = respuesta_id;
var d = document.getElementById(id_respuesta);
if( $('#corazon').prop('checked') ) {
heart = 1;
d.className += " no_me_gusta";
} else {
heart = 0;
d.removeClass("no_me_gusta");
}
console.log(id_respuesta);
console.log(heart);
$.ajax ({
type: 'POST',
url: 'proces_like.php',
data: { "corazon": heart, "id_respuesta":id_respuesta },
success:function(datos){
$("#resultado").html(datos);
}
});
};
</script>
And the part of the HTML for that script:
echo "<div class='botones_post'>";
echo "<p id='resultado'></p>";
echo "<form class='corazon_like' name='like' id='heart' title='Me gusta el post' action='foro.php?foro=Xbox%20One&subforo=General&hilo=Vamos%dale&ID=1' method='post'>";
echo "<input type='checkbox' id='corazon' name='corazon'>";
echo "<label id='" . $respuestas['ID'] . "' class='fa fa-heart' onclick='myFunction($respuesta_id)' for='corazon'></label>";
echo "</form>";
echo "<a href='#' title='Borrar post'><i class='fa fa-trash' aria-hidden='true'></i></a>";
echo "<a href='#' title='Reportar post'><i class='fa fa-ban' aria-hidden='true'></i></a>";
echo "</div>";