0

When I use .getAttribute() instead of .value. It assigns null to the local variable value instead of the string.

for(let el of document.querySelectorAll("input,select"))
{
    // this works
    let value = el.value;

    if(el.classList.contains("foo") == true)
    {
        // this returns null
        value = el.getAttribute("value");
    }

    settings[el.name] = value;
}

Any ideas why .getAttribute() is returning null instead of the value?

This is inside a vue component, not sure if that makes a difference.

John
  • 5,942
  • 3
  • 42
  • 79
  • 3
    Go through [this](https://stackoverflow.com/questions/11973678/difference-between-element-value-and-element-getattributevalue) post . – Swati Jun 16 '21 at 12:08
  • It's not recommended to manipulate the DOM in this way using vue since it's a data-driven framework – Boussadjra Brahim Jun 16 '21 at 12:11
  • @BoussadjraBrahim its getting the values, not setting them and its necessary since the select element is generated on load using a jQuery color picker plugin so it can't be bound. – John Jun 16 '21 at 12:13
  • 2
    I think @Swati is correct [Difference between Element.value and Element.getAttribute("value")](https://stackoverflow.com/questions/11973678/difference-between-element-value-and-element-getattributevalue) – evolutionxbox Jun 16 '21 at 12:14

0 Answers0