Last active
August 31, 2018 20:01
-
-
Save dtomasi/e98e2402232674c11638 to your computer and use it in GitHub Desktop.
get all urls from all children of element
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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