<input type=”text” value=”click” onclick=”textClicked()”>
<script>
function textClicked() {
document.write(‘Text clicked’); }
</script>
OR
<input id=’txt’ type=”text” value=”click”>
<script>
document.getElementById(‘txt’).onclick = function() { document.write('Text clicked'); }
</script>
Which of the above is better design practice? In my opinion it is the first one because of the re-usability it provides for function textClicked().
Thank you.
The second option is better:
As André Caron mentioned in comments, there is nothing preventing you from assigning a value to
onclickby name: