Fred J. Fred J. - 1 year ago 189
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>input').attr("disabled", 'true');

Answer Source

Assign $('#login2') to var:

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

$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);