Skip to content

Instantly share code, notes, and snippets.

@philchanet
philchanet / document.html
Last active December 1, 2021 12:56
Replace div content with partial html file
<div id="navbarHTML"></div>
@philchanet
philchanet / load-resize.js
Created June 27, 2018 10:09
Check window width on load and on resize
$(window).bind("load resize", function () {
let windowWidth = $(window).innerWidth();
if (windowWidth < 768) {
...
} else if (windowWidth < 1025) {
...
} else {
...
}
});
@philchanet
philchanet / collapse-parent.js
Created June 27, 2018 10:08
Bootstrap collapse - only one uncollapsed element at a time
$('#sidebar-collapse-parent').on('show.bs.collapse', function () {
$('#sidebar-collapse-parent .collapse.in').each(function () {
$(this).collapse('hide');
});
});
@philchanet
philchanet / select-class-open-modal.html
Created August 29, 2017 09:27
Open modal upon selection of an option in a select - class-based version
<select class="selectpicker actions-more" data-style="btn-default btn-xs" data-width="auto" data-container="body" title="Horse...">
<option disabled>Substitute</option>
<option value="withdraw">Withdraw</option>
<option value="comment">Comment</option>
<option value="viewlog">View log</option>
</select>
@philchanet
philchanet / format.js
Created June 27, 2017 07:58
Format numbers with separator
var n = 1234567890;
String(n).replace(/(.)(?=(\d{3})+$)/g,'$1,')
// "1,234,567,890"
// Replace $1, with $1. or $1space to change separator
@philchanet
philchanet / select-open-modal.js
Last active August 28, 2017 15:28
Open modal upon selection of an option in a select
$('select').change(function () {
if ($(this).val() == "thevalue") {
$('#themodal').modal('show');
}
});
@philchanet
philchanet / file-select.html
Created May 24, 2017 15:29
Bootstrap file select button
<label class="btn btn-default btn-file">
Browse <input type="file" style="display: none;">
</label>
@philchanet
philchanet / selectpicker-links.html
Created May 24, 2017 09:10
Add links to bootstrap-select options
@philchanet
philchanet / inline-style.css
Created April 13, 2017 08:39
Override inline styles with Css
div[style] {
background: yellow !important;
}
@philchanet
philchanet / toggle-stripes.js
Created March 21, 2017 13:33
Hide TR on bootstrapToggle change + update table stripes on row show/hide
$(function() {
$('#bootstrapToggleID').change(function() {
$('.label-accepted').closest('TR').toggleClass("hidden");
$("tr:not(.hidden)").each(function (index) {
$(this).toggleClass("stripe", !!(index & 1));
});
});
});