Skip to content

Instantly share code, notes, and snippets.

@JensVerneuer
Last active December 19, 2015 21:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JensVerneuer/6019323 to your computer and use it in GitHub Desktop.
Save JensVerneuer/6019323 to your computer and use it in GitHub Desktop.
Arguments are: selector: a css selector for the dom Elements Argument type: string callback: the function wich will be called for every matched element first argument is the Element with Type DOM Node Argument type: function domScope: (optional) part of the dom where to search, default is document Argument type: DOM node (object)
var eachQuerySelectorAll = function(selector, callback, domScope){
if(typeof(domScope==="undefined")){
domScope = window.document;
}
if(typeof(callback)==="undefined"){
return false;
}
if(typeof(selector)!=="string"){
return false;
}
[].forEach.call(domScope.querySelectorAll(selector), callback);
return true;
}
/***************
*
* Example:
*
**************/
(function(win, doc, undefined){
var log = function(c){
if(typeof(console) === "object"){
console.log(c);
return;
}
alert(c);
}
eachQuerySelectorAll('a:not([target="_blank"])', log, doc )
})(window, document)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment