Fred J. Fred J. - 2 years ago 243
jQuery Question

combining jQuery selectors

My IDE is complaining about in-efficient use of jQuery selector and I am wondering if there is a better way to do this. Thanks



$('#login2').addClass('inactive');
$('#login2>input').attr("disabled", 'true');

Answer Source

Assign $('#login2') to var:

var $login = $('#login2');

$login.addClass('inactive');
$login.find('input').prop('disabled', true);

Should also be able to chain, but (to me) can get messy:

$login.addClass('inactive').find('input').prop('disabled', true);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download