jQuery and HTML5
- August 15th, 2010
- By Ionut
- Write comment
As probably most of you know HTML 5 is currently under development as the next major revision of the HTML standard and is expected to be the next step that will change how the web looks.
I will try to show you a couple of the new things added in HTML5 and how much jQuery influenced the HTML5 development.
So what is new:
New selectors
-Finding elements by class:
-
document.getElementsByClassName("test");
-Finding elements by CSS syntax – very similar with jQuery selectors
-
document.querySelectorAll("table.test > tr");
Drag and drop
-
document.addEventListener('dragstart', function(event) {
-
event.dataTransfer.setData('text', 'Customized text');
-
event.dataTransfer.effectAllowed = 'copy';
-
}, false);
In this HTML5 javascript example you can see the callback style use like in jQuery.
Web Workers
-
main.js:
-
var worker = new Worker('extra_work.js');
-
worker.onmessage = function(event) { alert(event.data); };
-
-
extra_work.js:
-
self.onmessage = function(event) {
-
// Do some work.
-
self.postMessage(some_data);
-
}
So we will have easy-to-use multi-thread support in HTML5.
Web Storage
-
// use localStorage for persistent storage
-
// use sessionStorage for per tab storage
-
-
textarea.addEventListener('keyup', function () {
-
window.localStorage['value'] = area.value;
-
window.localStorage['timestamp'] = (new Date()).getTime();
-
}, false);
-
textarea.value = window.localStorage['value'];
Session support in Javascript.