Let suppose we have:
Let myVar = document.getElementbyId("Sample")
How can I process/modify the value in the javascript variable myVar
without affecting anymore the DOM object?
Anytime I do something like:
myVar.value = myVar.value + 100;
The DOM is altered too, since myVar is representing the DOM object, instead of only have caught its value.
Thanks in advance.
$('#btn').click(function(ev) {
var a = document.getElementById("myInput")
var b = a
b.value = "Why DOM changed?";
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<html>
<label>Original input value </label>
<br>
<input type="text" id="myInput" value="55"/>
<button id="btn">Modify Variable - NOT DOM Obj</button>
</html>