Skip to content

Instantly share code, notes, and snippets.

@Bloodb0ne
Created August 12, 2015 17:48
Show Gist options
  • Save Bloodb0ne/84dd3bc5f96df648f565 to your computer and use it in GitHub Desktop.
Save Bloodb0ne/84dd3bc5f96df648f565 to your computer and use it in GitHub Desktop.
Random Html Menu -> Json
function reparseElements($container){
return $container.map(function($ind,$item){
if($($item).children('ul').length != 0){
return {
title:$($item).children('a').text(),
children: reparseElements($($item).children('ul').children('li')).get()
};
}
return { title:$($item).children('a').text() };
});
}
var temp = $($0).find('li>div.submenu').map(function($ind,$item){
return {
title: $($item).children('.title').text(),
children: reparseElements($($item).children('ul').children('li')).get()
};
});
JSON.stringify(temp.get())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment