Skip to content

Instantly share code, notes, and snippets.

@andykillen
Last active June 18, 2016 14:10
Show Gist options
  • Save andykillen/b1931a4ea67752039a5f2cde8eb9508a to your computer and use it in GitHub Desktop.
Save andykillen/b1931a4ea67752039a5f2cde8eb9508a to your computer and use it in GitHub Desktop.
Its gives better performance to use a javascript object than it does to use a jQuery selector.
var el = document.getElementById('header'); // this is for #header not <header>
$(el).('.some-class-used-in-header').each(function(index){
// do something!! to each of the things with this class
});
$(el.getElementsByTagName('nav')).on('touchstart click', 'a', function(e){
// do something when an <A> inside a <NAV> inside #header is clicked.
e.preventDefault(); // prevents the default click action
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment