I want to convert this node list element to String and cut it to have only value "12803"
if (document.getElementById('sale_info_order_from').innerHTML.indexOf('JDG') != -1){
document.getElementById("invoice_text").style.outline = "thick solid green";
var elements = document.querySelectorAll('[onclick^=copyTextToClipboard]');
var element = elements[1];
console.log(element);
Result i have now is:
<span class="tip_trigger" data-original-title="Kopiuj do schowka" onclick="copyTextToClipboard('12803')">12803</span>
2
Answers
You seem to be looking for the element’s
innerText
; replacevar element = elements[1];
withvar element = elements[1].innerText;
You can get that value via
element.innerText
orelement.innerHTML
, depending on what values you may have. Ask yourself what you would want to do if the inner content of the tag would be a template. If you want to get it as HTML, theninnerHTML
should be your choice. Otherwise it’sinnerText
.