I think what you want is this where you use the .value
property on the input fields directly:
var clear = function() {
$("miles").value = "";
$("gallons").value = "";
$("mpg").value = "";
}
Here's an explanation of what was going on. Now that we can see your full page and see that $
is document.getElementById()
, the issue is that you are some of those nodes don't have a firstChild.
For example the object with an id="miles"
is an input tag and it has no children so .firstChild
is null
.
In this line:
$("miles").firstChild.nodeValue = "";
$("miles")
gets you the DOM object.
$("miles").firstChild
returns null because there are no children of that DOM object.
$("miles").firstChild.nodeValue = "";
is an error because $("miles").firstChild
is null
and null
doesn't have a property .nodeValue
.