Skip to content

Instantly share code, notes, and snippets.

@rccc
Last active August 29, 2015 14:09
Show Gist options
  • Save rccc/7444fa4f4224cdb1c871 to your computer and use it in GitHub Desktop.
Save rccc/7444fa4f4224cdb1c871 to your computer and use it in GitHub Desktop.

Navigation

Enfants

// jQuery
jQuery('#my-id').children()

// vanilla
document.getElementById('my-id').children // "children" est une propriété !

// jQuery
if($('#my-id').is(':empty'))

// Vanilla
if(!document.getElementById('my-id').hasChildNodes())

//http://api.jquery.com/category/selectors/content-filter-selector/
//https://developer.mozilla.org/fr/docs/DOM/element.hasChildNodes

Parent

// Jquery
jQuery('#my-id').parent()

// vanilla
document.getElementById('my-id').parentNode 

Frères

// Jquery
jQuery('#my-id').siblings()

// vanilla
var el = document.getElementById('my-id');
Array.prototype.filter.call(el.parentNode.children, function(child){
  return child !== el;
});

Élements précedants et suivants

// Jquery
jQuery('#my-id').prev()
jQuery('#my-id').next()

// vanilla
document.getElementById('my-id').previousElementSibling 
document.getElementById('my-id').nextElementSibling
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment