mardi 14 juillet 2020

jquery if condition after checking DOM element and checking element is exists

i have multiple div with the same class <div class="form-group"> when one of them clicked i adding class .current it's works but I had trouble adding conditions here the code..

HTML

<div class="form-group col-md-12" id="01">
   <div class="fieldPreview">...</div>
</div>
<div class="form-group col-md-12" id="01">
   <div class="fieldPreview">...</div>
</div>

jQuery

$('fieldset.settings').on('click', '.form-group:not(#title-form)', function() {    
var activeClass = $('fieldset.settings .form-group.current');
var removeCls = activeClass.removeClass('current');
var addCls = $(this).addClass("current");

// get the last current ID on div
var getIDlastActive = $(activeClass).attr('id');
// get the current div ID just added
var getIDjustActive = $(addCls).attr('id');
}

how to make conditions in order :

if(getIDlastActive == getIDjustActive AND getIDlastActive is children('.fieldPreview') visible true){}

i have tried code like this

if(getIDlastActive.indexOf(getIDjustActive) !== -1) {
    
}else{
    if($(getIDlastActive).children('.fieldPreview:visible').length !== -1){
        $('.fieldPreview').show();
}

what I want is that when it is clicked in the same place then it doesn't need to do anything but when others are clicked (moved), then display <div class="fieldPreview">

in other conditions I have hidden the div <div class="fieldPreview">

if anyone can help please..

Aucun commentaire:

Enregistrer un commentaire