javascript - Swapping text equal in different divs and classes -
i have several boxes of cards on 1 page, these boxes can come dynamically in different, not upper right corner has text click open accordion type content, each class have action below, think of regardless of number of classes.
*new
i not know how explain it, i'll try summary: change text of 1 div when clicking, because when click on item in box changes other texts of other boxes.
$('.change-1').click(function () { var $mudartxt = $('.mudartexto'); if ($mudartxt.text() == 'expandir') $mudartxt.text('ocultar'); else { $mudartxt.text('expandir'); } });
you need find current clicked item.
for can use event object
$('.change-1').click(function (e) { // current target jquery object var $target = $(e.currenttarget); // find mudartexto in current target. var $mudartxt = $target.find('.mudartexto'); if ($mudartxt.text() == 'expandir') $mudartxt.text('ocultar'); else { $mudartxt.text('expandir'); } });
.change-1 { display:inline-block; width:200px; height:50px; text-align: center; background-color:#dfdfdf; clear: both; float: left; margin-top:10px; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="change-1"> <div class="mudartexto">expandir</div> </div> <div class="change-1"> <div class="mudartexto">expandir</div> </div> <div class="change-1"> <div class="mudartexto">expandir</div> </div> <div class="change-1"> <div class="mudartexto">expandir</div> </div>
Comments
Post a Comment