I\'ve been looking for an answer to this question but I could find none so I thought I\'d try StackOverflow.
In javascript, is this valid:
x = document
This is a fast alternative based on Node.contains
var getById = function(id, context) {
var el = document.getElementById(id);
return context.contains(el) ? el : null;
}
var container = document.getElementById('container-element');
getById('my-element-id', container);
The last line (profiled on latest Chrome and Firefox) performs 4x to 10x faster than jQuery's equivalent
$('#my-element-id', container);
The only good alternative is querySelector (a bit faster)
container.querySelector('#my-element-id');