jquery's way of determining whether an HTML element exists

Source: Internet
Author: User

This article is mainly on the jquery to determine whether the existence of HTML elements of the two solutions are introduced, need friends can come to the reference, I hope to help you

In this case, the page part of the HTML element is controlled by the server-side language to display different content according to different circumstances, but on the same page in some cases when the DOM is ready to use AJAX and server communication, and some cases do not need, So I just want to be in the page when I specify the HTML tag to trigger the Ajax part, after all, this can reduce the burden on the server, a lot of nonsense, to the point: in fact, to solve the problem of jquery to determine whether the element exists, the method is simple: if ($ ("#abc"   >0) {...}   if ($ ("#abc"). html ()!= "") {...} There are two ways to determine whether an HTML document has the elements we want, and we tried using $ ("#abc")!= null/!$ ("#abc")/$.find ("#abc") ... The result is not, because regardless of whether the element exists will return object, then I temporarily use one of the above two methods to solve the problem, there is no better way to explore ...

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.