Skip to content

Instantly share code, notes, and snippets.

<div class="quantity">
<button type="button" id="add" class="add">+</button>
<input type="number" value="0" class="input-text qty text" />
<button type="button" id="sub" class="sub">-</button>
</div>
$('.add').on('click', function (){
var curVal = +$(this).parent().find('input').val();
$(this).parent().find('input').val(curVal + 1);
});
@Farmatique
Farmatique / gist:d162a6d6fb346c615577e8b2ddfe15f2
Created August 22, 2017 09:26
owl-carousel with prev/next images on nav arrows
var productColorSlider = $("#product-color-slider").find('.owl-carousel');
productColorSlider.on('initialized.owl.carousel', function(property) {
// its important to place initialized.owl.carousel before attaching owl-carousel
var current = property.item.index;
var prev = $(property.target).find(".owl-item").eq(current).prev().find("img").attr('src');
var next = $(property.target).find(".owl-item").eq(current).next().find("img").attr('src');
$('.navPrev').find('img').attr('src', prev);
$('.navNext').find('img').attr('src', next);
});
@Farmatique
Farmatique / gist:b6618880578d9eeb25cb0eb1f8a4b4ef
Created September 4, 2017 11:42
change class of element by choosing specific option from select
document.addEventListener("DOMContentLoaded", function(){
document.getElementById('id-of-select-box').addEventListener('change', function(e){
switch(e.target.value){
case 'Desirable option-value here':
document.getElementById('id-of-the-target-element').getElementsByClassName('class-of-the-target-element')[0].classList.add('hidden');
break;
default:
document.getElementById('id-of-the-target-element').getElementsByClassName('class-of-the-target-element')[0].classList.remove('hidden');
}
})
@Farmatique
Farmatique / gist:c969d9b1144a95787513f4f02fd2f485
Created September 12, 2017 16:31
Tricks for print media css
/* preserve color */
-webkit-print-color-adjust: exact;
@Farmatique
Farmatique / gist:6b59ea1c6fe4ee7c3f12fa9a4c39de19
Last active October 6, 2017 19:59
scroll top detect pure js
var scrollTop = (window.pageYOffset !== undefined) ? window.pageYOffset : (document.documentElement || document.body.parentNode || document.body).scrollTop;
/* using jquery */
var scrollTop = $(window).scrollTop()
if(window.innerWidth < 768)
@Farmatique
Farmatique / gist:78c0baef6d71e60a4138ee4165b76a7c
Created October 13, 2017 15:47
change look of checkboxes (if no ability to change layout of input wrappers)
<div class="checkbox">
<label class="checked">
<input type="checkbox"">
Implementation
</label>
</div>
.checkbox input[type="checkbox"]{
display: none;
}
@Farmatique
Farmatique / gist:fd825bef353b73761081f9fad6ba9347
Created October 23, 2017 19:49
Get maximum height from the set of elements
var maxHeight = Math.max.apply(null, jQuery(".section.resources-page .webinar >div").map(function ()
{
return jQuery(this).height();
}).get());
@Farmatique
Farmatique / gist:4433d7b9e6e6084b5c294595728d7a11
Created February 8, 2018 15:34
Find if array of objects have an object with specific property name
myArray.filter(x => x.id === '45')
// it returns array with an object if its find matching object
<span class="wpcf7-form-control wpcf7-radio">
<span class="wpcf7-list-item">
<label class="">
<input type="radio" value="Yes">
<span class="wpcf7-list-item-label">Yes</span>
</label>
</span>
</span>