How can I rewrite this jQuery to be more terse and without the guard clause?
var myTextBox = $('#myTextBox');
if (myTextBox )
myTextBox.val("");
The guard clause is there simply to ensure that the element exists on the page before trying to set it’s value but the code seems bloated and most of it unnecessary.
What’s the preferred solution to this?
$('#myTextBox').val("")will do nothing if the jQuery object has a length of0, so simply use it.