Created
February 21, 2018 18:09
-
-
Save mokanfar/4076c37f2dd9ad7b3230b58b57c59f7d to your computer and use it in GitHub Desktop.
$ jQuery snippets
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
//=========== | |
jQuery.noConflict(); | |
(function ($) { | |
$(this).remove(); | |
})(jQuery); | |
//=========== | |
//=========== | |
jQuery(document).ready(function() { | |
}); | |
//=========== | |
//=========== | |
jQuery( ".link" ).click(function(e) { | |
e.preventDefault(); | |
}); | |
//=========== | |
//=========== | |
var resizeTimer; | |
jQuery(window).on('resize', function(e) { | |
clearTimeout(resizeTimer); | |
resizeTimer = setTimeout(function() { | |
// Run code here, resizing has "stopped" | |
if(jQuery(window).width() < 492) { | |
} else { | |
} | |
}, 250); | |
}); | |
//=========== | |
//=========== | |
jQuery(el) | |
.css({ | |
"height": jQuery(this).height(), | |
"max-height": 9999 | |
}) | |
.animate({ | |
"height": totalHeight | |
}); | |
//=========== | |
//=========== | |
jQuery(document).ready(function($) { | |
/* getting viewport width */ | |
var responsive_viewport = $(window).width(); | |
/* if is below 481px */ | |
if (responsive_viewport < 481) { | |
} /* end smallest screen */ | |
/* if is larger than 481px */ | |
if (responsive_viewport > 481) { | |
} /* end larger than 481px */ | |
/* if is above or equal to 768px */ | |
if (responsive_viewport >= 768) { | |
} | |
/* off the bat large screen actions */ | |
if (responsive_viewport > 1030) { | |
} | |
}); | |
//=========== | |
//=========== | |
function preload(arrayOfImages) { | |
$(arrayOfImages).each(function(){ | |
$('<img/>')[0].src = this; | |
// Alternatively you could use: | |
// (new Image()).src = this; | |
}); | |
} | |
// Usage: | |
preload([ | |
'img/imageName.jpg', | |
'img/anotherOne.jpg', | |
'img/blahblahblah.jpg' | |
]); | |
//=========== | |
//=========== | |
var content = jQuery('.class').contents(); | |
jQuery('.class').replaceWith(content); | |
//=========== | |
//=========== | |
jQuery(el).addClass('asdf'); | |
jQuery(el).removeClass('asdf'); | |
jQuery(el).toggleClass('asdf'); | |
jQuery(el).click(function(){ }); | |
jQuery(el).mouseenter(function(){ }); | |
jQuery(el).mouseleave(function(){ }); | |
jQuery(el).hover(function(){ }); | |
jQuery(el).focus(function(){ }); | |
jQuery(el).blur(function(){ }); | |
jQuery(el).hide(); | |
jQuery(el).show(); | |
jQuery(el).toggle(); | |
jQuery(el).text('asdf'); | |
jQuery(el).html('asdf'); | |
jQuery(el).val(); | |
jQuery(el).attr(); | |
jQuery(el).append('asdf'); | |
jQuery(el).prepend('asdf'); | |
jQuery(el).after(); | |
jQuery(el).before(); | |
jQuery(el).remove(); | |
jQuery(el).empty(); | |
//=========== | |
//=========== | |
jQuery(document).ready(function(){ | |
jQuery("button").click(function(){ | |
jQuery("#div1").load("demo_test.txt", function(responseTxt, statusTxt, xhr){ | |
if(statusTxt == "success") | |
alert("External content loaded successfully!"); | |
if(statusTxt == "error") | |
alert("Error: " + xhr.status + ": " + xhr.statusText); | |
}); | |
}); | |
}); | |
<div id="div1"><h2>Let jQuery AJAX Change This Text</h2></div> | |
<button>Get External Content</button> | |
//=========== | |
//=========== | |
if (jQuery('#myElement').length > 0) { | |
/magento child block phtml | |
<?php $this->getChild('stock_info')->setData("product", $_product); ?> | |
<?php echo $this->getChildHtml('stock_info', false) ?> | |
<?php echo $this->getChildHtml('child_view') ?> | |
/ it exists | |
} | |
//=========== |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment