I stumbled upon something peculiar (at least to me). Here is the case:
I select an element, child1, from the DOM and save it to a variable. I continue on by adding a new element to child1's parent, parent1. Now if I try to modify some value on child1 it does not register the change. It seems as though the reference has disappeared and it is only referring to an earlier copy.
EXAMPLE
child1 = inputField
parent1 = container
function start() {
var inputField = document.querySelector('#inputField');
// Works if addSomething() is commented out.
addSomething();
console.log(inputField);
doSomething(inputField);
}
function addSomething() {
var container = document.querySelector('#container');
container.innerHTML += '<div class="something"></div>'
}
function doSomething(el) {
el.value = 'Some random input';
}
start();
EXAMPLE FIDDLE
Excuse me if this is something incredibly basic or something that has been asked before. I tried googling, but did not find anything with the search words I used. A