Last active
April 9, 2019 08:28
-
-
Save arturmamedov/2bdfc3f69828ac37a7a1 to your computer and use it in GitHub Desktop.
AngularJS show /hide VS jQuery show/hide.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- AngularJS ng-show and ng-click --> | |
<div class="checkbox"> | |
<label ng-click="show = !show"> | |
<input type="radio" name="cat_id" value="1"> | |
<strong>Residenziale</strong> Immobili in vendita oppure in affitto<br> | |
</label> | |
<span ng-show="show"> | |
<label class="checkbox-inline"> | |
<input type="radio" value="A" name="res_sell_type"> | |
Affitto | |
</label> | |
<label class="checkbox-inline"> | |
<input type="radio" value="V" name="res_sell_type"> | |
Vendita | |
</label> | |
</span> | |
</div> | |
<!-- jQuery selector on click toggle --> | |
<div class="withBox checkbox"> | |
<label class="showhideBox"> | |
<input type="radio" name="cat_id" value="2"> | |
<strong>Commerciale</strong> Immobili, attività e licenze, terreni in vendita oppure in affitto<br> | |
</label> | |
<span class="shBox display-none"> | |
<label class="checkbox-inline"> | |
<input type="radio" value="A" name="com_sell_type"> | |
Affitto | |
</label> | |
<label class="checkbox-inline"> | |
<input type="radio" value="V" name="com_sell_type"> | |
Vendita | |
</label> | |
</span> | |
</div> | |
<script> | |
$(".withBox").on('click', ".showhideBox", function(){ | |
var thisBox = $(this).parent(); | |
$(".shBox", thisBox).toggle('fast'); | |
$(".shSwitch", thisBox).toggle(1); | |
}); | |
</script> | |
<!-- jQuery collapsable selector on click toggle hasClass mouseup --> | |
<div class="withBox collapsable checkbox"> | |
<label class="showhideBox"> | |
<input type="radio" name="cat_id" value="2"> | |
<strong>Commerciale</strong> Immobili, attività e licenze, terreni in vendita oppure in affitto<br> | |
</label> | |
<span class="shBox display-none"> | |
<label class="checkbox-inline"> | |
<input type="radio" value="A" name="com_sell_type"> | |
Affitto | |
</label> | |
<label class="checkbox-inline"> | |
<input type="radio" value="V" name="com_sell_type"> | |
Vendita | |
</label> | |
</span> | |
</div> | |
<script> | |
$(".withBox").on('click', ".showhideBox", function(){ | |
var thisBox = $(this).parent(); | |
$(".shBox", thisBox).toggle('fast'); | |
$(".shSwitch", thisBox).toggle(1, function(){ | |
if($(this).hasClass('set')) | |
$(this).removeClass('set'); | |
else | |
$(this).addClass('set'); | |
}); | |
}); | |
// no close on himself click | |
$(".withBox.collapsable").mouseup(function(){ return false; }); | |
// close on document click | |
$(document).mouseup(function(){ | |
$(".shBox", $(".withBox.collapsable")).slideUp(); | |
var shSwitch = $(".shSwitch", $(".withBox.collapsable")); | |
if(shSwitch.hasClass('set')) | |
shSwitch.toggle(1, function(){ | |
if($(this).hasClass('set')) | |
$(this).removeClass('set'); | |
else | |
$(this).addClass('set'); | |
}); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Also https://getbootstrap.com/docs/4.1/components/collapse/