JQuery determines whether an element is visible.

Source: Internet
Author: User

JQuery determines whether an element is visible.

This article describes how jQuery judges whether an element is visible. Share it with you for your reference. The details are as follows:

JQuery can easily determine whether an element is visible or hidden, and then perform different processing. For example, I want to display different text and icons on the button based on whether a div is visible. This can be achieved as follows:

Method 1:

$ ('# Para_div button '). click (function () {if ($ (this ). next (). is (": visible") {// ((this).html ('display'); $(this).css ({"background": "url (/images/btn_arrow_down.png) no-repeat "});} else {// response (this).html ('hiding '); Response (this).css ({" background ":" url (/images/btn_arrow_up.png) no-repeat "}) ;}$ (this ). next (). slideToggle ('fast ');});

Method 2:

$ ('# Para_div button '). click (function () {if(((this).next().css ('display') = 'None') {// hide (this).html ('hiding '); then (thisground .css ({"background ": "url (/images/btn_arrow_up.png) no-repeat"});} else {// ((this).html (' '); $(thisground .css ({"background ": "url (/images/btn_arrow_down.png) no-repeat"});} $ (this ). next (). slideToggle ('fast ');});

Method 3:

$ ('# Para_div button '). click (function () {var $ cn = $ (this ). next (); // certificate (this).html ($ cn. is (": visible "))? 'Display': 'hiding '); (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 jQuery programming.

Related Article

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.