Last active
August 21, 2020 17:00
-
-
Save MichaelDimmitt/5a122733e1ff4bb11a453dc73582be61 to your computer and use it in GitHub Desktop.
Given a nested html lists return the top level.
This file contains hidden or 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
// used to simplify: http://www.databaseanswers.org/data_models/index.htm | |
// and http://www.databaseanswers.org/data_models/index_all_models.htm | |
var parentList = document.getElementsByTagName('li'); | |
for(var x = 0; x < parentList.length; x++) { | |
var childList = parentList[x].getElementsByTagName('ol') | |
for(var y = 0; y < childList.length; y++) { | |
childList[y].remove() | |
} | |
} |
This file contains hidden or 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
// used to simplify: http://www.databaseanswers.org/data_models/index.htm | |
// and http://www.databaseanswers.org/data_models/index_all_models.htm | |
var parentList = document.getElementsByTagName('li'); | |
for(var x = 0; x < parentList.length; x++) { | |
var childList = parentList[x].getElementsByTagName('ol') | |
for(var y = 0; y < childList.length; y++) { | |
var parentList2 = childList[y].getElementsByTagName('li'); | |
for(var a = 0; a < parentList2.length; a++) { | |
var childList2 = parentList2[a].getElementsByTagName('ol') | |
for(var b = 0; b < childList2.length; b++) { | |
childList2[b].remove() | |
} | |
} | |
} | |
} |
This file contains hidden or 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
// used to simplify: http://www.databaseanswers.org/data_models/index.htm | |
// and http://www.databaseanswers.org/data_models/index_all_models.htm | |
const findChildItems = (domValues) => { | |
var parentList = domValues.getElementsByTagName('li'); | |
var childList = document.createDocumentFragment().children | |
if(parentList){ | |
for(var x = 0; x < parentList.length; x++) { | |
childList = [...childList, ...parentList[x].getElementsByTagName('ol')] | |
console.log(childList) | |
} | |
} | |
return childList | |
} | |
const removeItems = (list) => { | |
for(var x = 0; x < list.length; x++) { | |
list[x].remove() | |
} | |
} | |
removeItems( | |
findChildItems( | |
document | |
) | |
) | |
// removeItems( | |
// findChildItems( | |
// findChildItems( | |
// document | |
// ) | |
// ) | |
// ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment