Jetbrains PHPStorm 5.0.4 tells me I have a Duplicated jQuery Selector

后端 未结 1 2085
一生所求
一生所求 2021-02-19 06:15

This is the piece of jQuery I wrote,

$(\'#editUser\').click(function() {
    if ($(\".selectedTR\")[0]) {
        if($(\'.form-actions\').is(\':visible\')) {
            


        
1条回答
  •  你的背包
    2021-02-19 07:12

    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");
        }
    });
    

    0 讨论(0)
提交回复
热议问题