Pedro Chaves
Pedro Chaves

Reputation: 13

Button onclick only works once

I have this html code for "Comentário" section:

<div class="col-lg-1">
 <button title="Editar" type="submit" class="btn btn-info btn-sm pull-right" onclick="editar({{$feedback->id}})">
  <span class="fa fa-pencil"></span>
 </button>
</div>

<div class="col-lg-10" id="esconde{{$feedback->id}}">
 <span class="textoInfo"><b>Comentário:</b></span>
 <br>
 {{$feedback->comentario}}
</div>

<div class="col-lg-10" id="mostra{{$feedback->id}}" style="display:none;">
 <span class="textoInfo"><b>Comentário:</b></span>
    <div class="input-group" id="showComent{{$feedback->id}}">
     {{ Form::text('comentario',$feedback->comentario, ['class' => 'form-control input-sm', 'id' =>'textcoment'.$feedback->id]) }}
    <div class="input-group-btn">
      <button id="sendComent" type="submit" class="btn btn-info btn-sm" onclick="submitComent({{$feedback->id}})"><span class="fa fa-play"></span>   </button>  
    </div>
  </div>    
</div>

And this jquery code:

<script type="text/javascript">
 function editar(id) {  
   $('#esconde'+id).hide();
   $('#mostra'+id).show();
 } 
</script>

The problem is that the the function onclick only works once. Is there a way to reload the #mostra div only? Or other simple way to do it. Thanks :)

Upvotes: 0

Views: 312

Answers (2)

Pedro Chaves
Pedro Chaves

Reputation: 13

It´s working. It was a matter of logic. I used show/hide functions. But I would keep toogle suggestion in mind. Thanks :)

Upvotes: 0

Koen van den Heuvel
Koen van den Heuvel

Reputation: 765

I am not sure what you are trying to achieve but I assume you want to toggle one of the elements when someone presses the button. You have two options here really.

  1. You can use the jQuery function .toggle() to toggle the element.

  2. You can use .is(':visible') to see if the element is visible or not in a if statement and go from there.

Upvotes: 3

Related Questions