I have the following code. Its working fine but im wondering if the 3rd line is best practice. When the element myID is on the page its attributes is changed. However its not on every page so often this does nothing. This seems harmless to me but are there any downsides im not aware of?
$(document).ready(function () {
if ($(window).width() < 700) {
$('#myID').attr('size', 1)
}
});
From jquery attr doc
The
.attr()method try to set attribute on the first element of jquery object. If jquery object is empty then nothing happens.