jquery's method of determining whether an element is visible

Source: Internet
Author: User

This example describes how jquery can determine whether an element is visible. Share to everyone for your reference. Specifically as follows:

JQuery can easily determine that an element is visible or hidden, and then do a different processing separately. For example, I want to display different text and icons on a button based on whether a div is visible. This can be accomplished by:

Method One:

?

1 2 3 4 5 6 7 8 9 10 11 $ (' #para_div button '). Click (function () {if ($ (this). Next (). are (": visible")) {//$ (this). HTML (' Display '), $ (this). CSS ({" Background ":" url (/images/btn_arrow_down.png) no-repeat "}); else {//$ (this). html (' hide '); $ (this). CSS ({"Background": "url (/images/btn_arrow_up.png) no-repeat"}), $ (this). Next ( ). Slidetoggle (' fast '); });

Method Two:

?

1 2 3 4 5 6 7 8 9 10 11 $ (' #para_div button '). Click (function () {if ($ (this). Next (). CSS (' display ') = = ' None ') {//$ (this). html (' hide '); $ (this). CSS ({"Background": "url (/images/btn_arrow_up.png) no-repeat"});  } else{//$ (this). HTML (' Display '); $ (this). CSS ({"Background": "url (/images/btn_arrow_down.png) no-repeat"}); $ (this). Next (). Slidetoggle (' fast '); });

Method Three:

?

1 2 3 4 5 6 7 8 $ (' #para_div button '). Click (function () {var $CN = $ (this). Next (),//$ (this). HTML ($CN. Is (": visible"))? ' Show ': ' Hidden '); (this). CSS ($CN. Is (": visible"))? {"Background": "url (images/btn_arrow_down.png) no-repeat"}: {"Background": "url (images/btn_arrow_up.png) no-repeat" }); $CN. Toggle (' fast '); });

I hope this article will help you with your jquery programming.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.