r/JavaScriptHelp • u/juggling-monkey • Mar 13 '21
✔️ answered ✔️ Need help storing parent classes into array (possibly with recursion)
I'm trying to take html that looks like this:
<div data-condition=" noise = 'purr' ">
<div class="include" data-include="cat"></div>
</div>
<div data-condition=" noise = 'bark' ">
<div data-condition=" tail = 'wag' ">
<div class="include" data-include="dog"></div>
</div>
</div>and convert it to an object that looks like this
data = {
cat: { noise: 'purr' },
dog: { noise: 'bark', tail: 'wag' }
}I have a file with over a hundred of these blocks, and need to log (into the object) what generates each data-include. hoping someone can help. I'm using jquery but vanilla Js works as well. thanks!