<div id="~" class="dm-post-0 well clearfix post listview"
data-identifier="~" data-relative="https://url_that_i_want_to_capture"
data-feed="~">
let convertEntries = () => {
"use strict";
let target = [...document.getElementsByClassName("listview")];
let result = [];
target.forEach((element) => {
result.push({
title: element.querySelector(".list-header strong").textContent,
url: element.querySelector("#listview").dataset.relative,
});
});
return result;
};
I can now capture just the text within the strong
tag. However, I cannot capture the data-relative
attribute.
3
Answers
for the first question i’d suggest using
use
.getAttribute("data-relative")
to get the value of the attribute"data-relative"
or use
.dataset.relative
to get the value of the attribute"data-relative"
You can use the querySelector method to find the strong element within the div, and then use the textContent property to get the text within it. You can better understand.
Try this:
You can use "for of" loop for all strong elements
You can do it like this
var element = document.querySelector(".list-header strong").textContent;
to get the text inside the strong element inside your list-header class andvar element2 = document.querySelector(".listview").getAttribute('data-relative');
to get the attribute