This is the piece of jQuery I wrote,
$('#editUser').click(function() {
if ($(".selectedTR")[0]) {
if($('.form-actions').is(':visible')) {
$('.form-actions').slideUp('slow',function() {
$('.form-actions > h3').text("Edit");
}).css('display', 'none');
}
$('.form-actions').css('display', 'block').slideDown('slow');
} else {
alert("Please select a user");
}
});
How can I remove the duplicated selectors?
You can cache the selector by putting it in a variable. Try this:
$('#editUser').click(function() {
if ($(".selectedTR").length) {
var $formActions = $('.form-actions');
if ($formActions.is(':visible')) {
$formActions.slideUp('slow', function() {
$formActions.children('h3').text("Edit");
}).css('display', 'none');
}
$formActions.css('display', 'block').slideDown('slow');
} else {
alert("Please select a user");
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With