skip to Main Content

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


  1. You seem to be looking for the element’s innerText; replace var element = elements[1]; with var element = elements[1].innerText;

    Login or Signup to reply.
  2. You can get that value via element.innerText or element.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, then innerHTML should be your choice. Otherwise it’s innerText.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search