Problem with jquery selector

I have a function that I can call to apply a rounded corner correction to the button.button, button.ui-button, input.button and input.ui-button 'button, which simply adds a div next to the element and then wraps the whole batch in another div.

It works great when loading a page, but I had to make a function that I could call to fix buttons that were not available when loading the page.

$(document).ready(function(){
    // Adds necessary div elements to buttons on page load.
    $('input.button:visible, button.button:visible, input.ui-button:visible, button.ui-button:visible').after('<div class="button-right"></div>').wrap('<div class="button-wrapper" />');
    $('input.button-large:visible, button.button-large:visible').after('<div class="button-large-right"></div>').wrap('<div class="button-large-wrapper" />');
});
function CheckIEButtons(){
    // Function to add necessary div elements to buttons - useful for buttons not accessible on page load
    $("input.button:visible:not(div.button-wrapper),button.button:visible:not(div.button-wrapper)").after('<div class="button-right"></div>').wrap('<div class="button-wrapper" />');
    $("input.ui-button:visible:not(div.button-wrapper),button.ui-button:visible:not(div.button-wrapper)").after('<div class="button-right"></div>').wrap('<div class="button-wrapper" />');
    $("input.button-large:visible:not(div.button-large-wrapper),button-large.button:visible:not(div.button-large-wrapper)").after('<div class="button-large-right"></div>').wrap('<div class="button-large-wrapper" />');
}

So, I basically want to select all the buttons / inputs with the corresponding class that ARE are visible but NOT in the wrapper of the div.

Whenever I call a function at the moment, its adding divs regardless of whether it is already in one.

+3
1

.button-wrapper , , .button-wrapper.

// parent isn't button-wrapper-----------v --------------------------------------------------------v
$("input.button:visible:not(div.button-wrapper > input.button),button.button:visible:not(div.button-wrapper > button.button)")

.

, not .not():

$("input.button:visible,button.button:visible").not(function() {
    return $(this.parentNode).hasClass( "button-wrapper" );
})...
+1

Source: https://habr.com/ru/post/1777082/


All Articles