Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Anyway to programmatically hide a jQuery UI button?

I'd like to do something like this, with jQuery UI Button:

$button.button();
// ...
$button.button('hide');
// ...
$button.button('show');

Similar to how enable/disable works. Hiding and showing the button manually ($button.hide(); $button.show();) is resulting in some really screwy formatting with the jQuery UI CSS...

Am I missing something simple here?

like image 639
neezer Avatar asked Jul 12 '26 02:07

neezer


2 Answers

Just doing the standard $button.hide() should do the job fine, what exactly is it screwing up?

You could do $button.css('display', 'none') but this is all that $button.hide() does anyway.

I'm pretty sure there isn't a way to do what you ask, and even if there would it only set display: none like the methods I just mentioned. You might be better of figuring out why setting display none is screwing up your CSS elsewhere on the page.

like image 109
jcvandan Avatar answered Jul 17 '26 19:07

jcvandan


If you use the style visibility instead of display the button should be able to create properly. The visibility: hidden style just makes the element invisible; the display: none style which $.hide() uses actually removes the element from the rendered DOM.

So in short try:

var newButton = $('a#some-button.hidden');

// Hide element, but allow it to use render space
newButton.attr('visibility', 'hidden');
newButton.attr('display', 'block');

// Create button
newButton.button();

// Revert element to the "normal" means of hiding (may be unnecessary)
newButton.attr('display', 'none');
newButton.attr('visibility', 'visible');

// Show button
newButton.show();

I've had to do this a few time before.

like image 24
JoshNaro Avatar answered Jul 17 '26 19:07

JoshNaro



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!