Skip to content

Instantly share code, notes, and snippets.

@arturmamedov
Last active April 9, 2019 08:28
Show Gist options
  • Save arturmamedov/2bdfc3f69828ac37a7a1 to your computer and use it in GitHub Desktop.
Save arturmamedov/2bdfc3f69828ac37a7a1 to your computer and use it in GitHub Desktop.
AngularJS show /hide VS jQuery show/hide.
<!-- 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>
@arturmamedov
Copy link
Author

@arturmamedov
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment