Just to be clear, clear()
is perfectly valid Vanilla Javascript.
It just so happens that document
defines a clear()
also:

...and since your HTML attribute assigned click handler gets executed with a modified scope chain, the document
object's clear()
comes before your global function in the scope chain (from Javascript: The Definitive Guide):
Event handlers registered as HTML attributes are a special case,
however. They are converted into top-level functions that have access
to global variables but not to any local variables. But, for
historical reasons, they run with a modified scope chain. Event
handlers defined by HTML attributes can use the properties of the
target object, the containing object (if there is one), and the
Document object as if they are local variables.
and then he discusses your exact case:
the modified scope chain of HTML event handlers is a source of
pitfalls, since the properties of each of the objects in the chain
shadow any properties of the same name in the global object. The
Document object defines a (rarely used) open() method, for example, so
an HTML event handler that wants to invoke the open() method of the
Window object must explicitly write window.open instead of open
so, your function could be reached via window.clear()
in the HTML:
function clear() { document.getElementById("customerName").value="";
}
<table border="1" id="orderForm">
<tr>
<th colspan="2">Customer Details</th>
</tr>
<tr>
<td id="font">Customer Name</td>
<td><input type="text" id="customerName"></td>
</tr>
</table>
<button type="button" id="button1" onClick="window.clear()">Clear</button>