labas GamePage visogero labas GamePage visogero - 2 months ago 20
Javascript Question

jQuery replaceWith() $this

I need to hide "show replies" when I click to show them. Problem is that when I click "show replies" all "show replies" buttons hides. I need to hide only that the one I click. This is the jQuery code:

$(".replies_show").click (function(e){
$(".replies_show").replaceWith(" ");


$(".replies_show") selects all elements having the class, therefore you are selecting all of them and then applying replaceWith to all of them again. However, this inside that call back function refers to the element that just clicked (i.e. the only clicked element not all of them).

Also, do not use replaceWith function just to hide an element, use .hide() instead.

So, replace

$(".replies_show").replaceWith(" ");