Created
October 24, 2013 20:14
-
-
Save yaph/7144195 to your computer and use it in GitHub Desktop.
Convert an HTML ul list of links to a JSON list of objects with href and text content.
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
var list = []; | |
$('ul a').each(function(idx, item){ | |
list.push({ | |
href: $(item).attr('href'), | |
text: item.textContent | |
}); | |
}); | |
JSON.stringify(list, null, " "); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@diegooCF yes
idx
is how I abbreviateindex
. It is not used in this snippet, that's just how the callback foreach
is defined in jQuery, see https://api.jquery.com/jQuery.each/