On every document ready I need to get the body tag via jQuery and I’m more curious about the answer to this than anything else.
Let’s say this is the body tag on every page on my site:
<body id="body">
Is it faster to query the body tag by just the tag name:
$('body')
or query it by its id:
$('#body')
The fastest way would be
$(document.body).This doesn’t involve any selector parsing.
$('body')is much faster (in Firefox and Chrome) than$('#body').Test