JavaScript get data attributes from nodeList?

javascript

Solution

var list = document.querySelectorAll('.class1 .class2 div[data-example]');
console.log(list[list.length - 1].getAttribute('data-example'));

http://jsbin.com/luyovumu/1/

Problem

I'm trying to webscrape data attributes. ``` <div class="class1"> <div class="class2"> <div data-example="hi"> </div> </div> </div> <div class="class1"> <div class="class2"> <div data-example="hi"> </div> </div> </div> ``` JavaScript ``` var list = document.querySelectorAll('.class1 .class2'); console.log(list[list.length - 1]); ``` This returns raw HTML in the console, which I can't use to access the data-attribute values. Unfortunately, I cannot change the format of the HTML and I'm only interested in getting `data-example` when it's from `.class1 .class2`. I'm getting HTML when I access any of the results from `querySelectorAll`.

Original source