Use jQuery Wisely

jQuery is a big library and isn’t always necessary. If you have a page where you only need to locate an element by its ID, stick with

 
navbar = document.getElementById(​"#navbar"​);

Loading jQuery for one or two things might be overkill. Modern browsers can already do a lot of what jQuery does with methods like document.querySelector and document.querySelectorAll, which are used in modern browsers to select elements using CSS selector syntax much like jQuery does:

 
links = document.querySelectorAll(​"a.popup"​);

Use jQuery when it makes your life easier, but don’t be afraid to leave it out when that makes more sense.

This is only a small sample of what we can do with jQuery. Aside from the document-manipulation features, ...

Get HTML5 and CSS3, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.