In this case, some HTML elements on the page are controlled by the server language to display different content according to different situations, however, in some cases on the same page, Ajax is required to communicate with the server after DOM preparation, but in some cases, so I only want to trigger the Ajax part when the page contains the HTML Tag I specified. After all, this can reduce the burden on the server. There is a lot of nonsense:
In fact, the method for JQuery to determine whether an element exists is simple:
If ($ ("# abc"). length> 0 ){...}
If ($ ("# abc" ).html ()! = ""){...}
Both of the above methods can determine whether html documents have the elements we want. We have tried $ ("# abc") before ")! = Null /! $ ("# Abc")/$. find ("# abc ")..... the result is not correct. no matter whether the element exists or not, the Object will be returned. Now, I have used one of the above two methods to solve the problem. Is there a better solution ......