开发者

Jquery Toggle On and Off

开发者 https://www.devze.com 2023-01-25 12:11 出处:网络
So I can use toggle do show/hide a dom element. Now I need only when the toggle makes the element visible to ma开发者_开发问答ke another action. How can I do that ?Yes, as naugtur says, you could use

So I can use toggle do show/hide a dom element. Now I need only when the toggle makes the element visible to ma开发者_开发问答ke another action. How can I do that ?


Yes, as naugtur says, you could use the version of toggle that allows you to specify exactly what you do when toggling each way.

Another option might be to test the visibility of the item in your existing toggle's event handler, e.g.:

$("#whatever").toggle(0, function() {
    if ( $(this).is(':visible')) {
        alert ("The thing is visible.");
    }
});

...will toggle "whatever", and then show the alert only when it's toggled visible.


It is true that selecting a dom element using a jQuery selector and using toggle() will switch the visibility of this elment on and off:

$('div:first').toggle();

The atomic steps of toggle() are show() and hide(). So if you only want to show a hiodden element use

$('div:first').show();

for further reference have a look at the jQuery API.

If you want to add another action onToggle you will need to add a handler for this action.


If I understand your question correctly, you want only to show an element, not toggle it show/hide. If this is correct, the solution is HERE

The usage is the same as toggle(), but the function is show()

0

精彩评论

暂无评论...
验证码 换一张
取 消