Skip to content

Instantly share code, notes, and snippets.

@lankaapura
Created March 11, 2016 09:11
Show Gist options
  • Save lankaapura/29c6cf087a4ad86c4744 to your computer and use it in GitHub Desktop.
Save lankaapura/29c6cf087a4ad86c4744 to your computer and use it in GitHub Desktop.
JQuery 3 Samples
////// 1.1 FOR...OF LOOP
// let’s say that you want to assign an ID to each input element of a page
//OLD
var $inputs = $('input');
for (var i = 0; i < $inputs.length; i++) {
$inputs[i].id = 'input-' + i;
}
//NEW
var $inputs = $('input');
var i = 0;
for (var input of $inputs) {
input.id = 'input-' + i++;
}
////// 1.2 New signature for $.GET() AND $.POST()
//OLD
jQuery.get(url[, data][, success][, dataType])
$.get("ajax/test.html", function(data) {
$(".result").html(data);
alert("Load was performed.");
});
//NEW
$.get([settings])
$.post([settings])
$.get({
url: "ajax/test.html",
data: data,
success: success,
dataType: dataType
})
// KEEP IN MIND : method property is always ignored.
$.get({
url: 'https://www.audero.it',
method: 'POST' // This property is ignored
});
////// 1.3 Use of REQUESTANIMATIONFRAME() for animations
//;;;
////// 1.4 UNWRAP() Improvements
https: //jsfiddle.net/bfwno6s5/
////// 1.5 Better handling of error cases
https: //jsfiddle.net/tkap55b3/
////// 2.1a :VISIBLE and :HIDDEN Improvements
http: //jsperf.com/sizzle-skip-qsa-vs-try-catch
////// 2.1b show() and hide() perf improvements
http: //jsperf.com/old-vs-new-show-hide/3
////// 2.2 DATA()
https: //jsfiddle.net/ccrvfcod/
////// 2.3 The DEFERRED object
// jQuery 3 changes the behavior of the Deferred object,
// a precursor of the Promise object,
// to improve its compatibility with the Promise/A+ proposal.
https: //jsfiddle.net/L2z6v8mx/1/
////// 2.4 SVG documents
////// 3.1 No IE6-8 support
////// 3.2 BIND(), UNBIND(), DELEGATE() and UNDELEGATE()
////// 3.3 LOAD(), UNLOAD() and ERROR()
< img src = "space-needle.png"
alt = "Space Needle"
id = "spacen" >
$("#spacen").load(function() {
// Handler implementation
});
$("#spacen").on("load", function() {
// Handler implementation
});
////// 3.4 CONTEXT, SUPPORT and SELECTOR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment