After studying the docs for a while, I came up with my first jQuery script. It's a simple Form Focus script. Just want to make sure I've got this right.
I couldn't find anything that spoke of "conditional statements" with jQuery, so I assume you just use standard JavaScript if
/ else if
statments.
To test if the #id
exists, the jQuery docs explained I should use .length
.
$(document).ready( function() {
if ($('#one').length) {
$('#one').focus();
}
else if ($('#two').length ) {
$('#two').focus();
}
else {
return false; // is this even necessary?
}
});
EDIT:
It is possible that #one
and #two
will exist on the same page, so I want to target #one
first.