Skip to content

Instantly share code, notes, and snippets.

@dtomasi
Last active August 31, 2018 20:01
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 dtomasi/e98e2402232674c11638 to your computer and use it in GitHub Desktop.
Save dtomasi/e98e2402232674c11638 to your computer and use it in GitHub Desktop.
get all urls from all children of element
/**
* Plugin for Loading urls eg. href-attribute from children of an Element
* may be to get all Links from a Navigation
*
* @copyright tomasiMEDIA 2013
* @author Dominik Tomasi
* @date 09.10.13
*
*/
(function($){
//returns href-Attributes value of all children in an array
$.fn.getHrefFromChildrenAsArray = function( elementSelector ){
var $this = $(this);
var data = [];
var selector;
if ( !elementSelector ){
selector = 'a';
} else {
selector = elementSelector;
}
$this.find(selector).each(function(){
data.push($(this).attr('href'))
});
return data;
};
//returns href-Attributes value of all children in an object
$.fn.getHrefFromChildrenAsObject = function( elementSelector ){
var $this = $(this);
var data = {};
var selector;
if ( !elementSelector ){
selector = 'a';
} else {
selector = elementSelector;
}
$this.find(selector).each(function(i){
data[i] = $(this).attr('href');
});
return data;
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment