Last active
February 4, 2020 16:57
-
-
Save ederrafo/8faab07e1e86ae1b29fb to your computer and use it in GitHub Desktop.
js javascript
This file contains hidden or 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
// load script after end load DOM | |
function downloadJSAtOnload() { | |
var element = document.createElement("script"); | |
element.src = "defer.js"; | |
document.body.appendChild(element); | |
/* | |
$("div.container-loader").removeClass('hidden'); | |
$.get( "./temporal.php", function( data ) { | |
$("#myCarousel").carousel("pause").removeData(); | |
$('[class^="carousel-"]').removeClass('hidden'); | |
$("div.epe-carousel").html(data); | |
$("div.container-loader").addClass('hidden'); | |
$('#myCarousel').carousel(); | |
}); | |
*/ | |
} | |
if (window.addEventListener) | |
window.addEventListener("load", downloadJSAtOnload, false); | |
else if (window.attachEvent) | |
window.attachEvent("onload", downloadJSAtOnload); | |
else | |
window.onload = downloadJSAtOnload; | |
// delete empty in array | |
existence.filter(Boolean) | |
existence = existence.filter(x => !!x); | |
existence[index] = null; | |
//convert string to array | |
var array = JSON.parse("[" + $("input#parameters").val() + "]"); | |
//count the number of element of same class in a div? | |
$('#main-div .specific-class').length | |
//otherwise with plain js (from IE8 included) you could simply write | |
document.querySelectorAll('#main-div .specific-class').length; | |
// Check #x | |
$( "#x" ).prop( "checked", true ); | |
// Uncheck #x | |
$( "#x" ).prop( "checked", false ); | |
$('#myCheckbox').attr('checked', true); // Checks it | |
$('#myCheckbox').attr('checked', false); // Unchecks it | |
$('div.section.filter:eq(1) input[type="checkbox"]').prop( "checked", true ); | |
$('div.section.filter:eq(1) input[type="checkbox"]').each(function() { | |
$(this).prop( "checked", false ); | |
}); | |
/* check if jquery has been loaded, then load it if false */ | |
<script> | |
if(!window.jQuery) | |
{ | |
var script = document.createElement('script'); | |
script.type = "text/javascript"; | |
script.src = "path/to/jQuery"; | |
document.getElementsByTagName('head')[0].appendChild(script); | |
} | |
</script> | |
/* native selector*/ | |
document.querySelector(".example"); | |
var element = document.querySelector("input[name=" + errors[i].name); | |
/*native selector checkbox*/ | |
var creditCards = document.querySelectorAll("input[name=creditCard]"); | |
for (var i = 0; i < creditCards.length; i++) { | |
creditCards[i].checked = false; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment