4 ms·
Some quickie improvements to the jQuery examples: $('body ul').append($('<li>')); can become: $('body ul').append('<li>'); and: $(document.body
by jeresig 16y ago
Some quickie improvements to the jQuery examples:
$('body ul').append($('<li>'));
can become:
$('body ul').append('<li>');
and:
$(document.body).find('ul li:last-child').text("I'M THE OLD GUY!");
can become:
$("body").find('ul li:last-child').text("I'M THE OLD GUY!");
(We optimize for body explicitly in our selector code.) Although that last example selector is rather weird, it's equivalent to:
$("body ul li:last-child")
or even just:
$("ul li:last-child")
(When is a ul ever going to be outside of a body element?)
- Sephr 16y agodocument.body.ƒ('ul li:last-child').innerText = "I'M THE NEW GUY!"; That code won't work in standards-compliant browsers. You should either use .textContent = "..." or .appendChild(document.createTextNode("...")) or .firstChild.wholeText = "..." if there's already a text node child. The real issue though is that unlike jQuery, ƒu.js won't work in popular versions of IE.
- masklinn 16y agoWell apart from the first one (clearly my mistake) I was trying to translate the original semantics as closely as possible. Hence the repeated (if not very useful) `body` anchors. > (When is a ul ever going to be outside of a body element?) Document fragments? XML documents? Not sure you can use that style of jQuery calls on those, but~~