Home > Web Front-end > JS Tutorial > How to determine if an element exists in jquery

How to determine if an element exists in jquery

coldplay.xixi
Release: 2020-11-16 10:49:02
Original
7860 people have browsed it

Jquery method to determine whether an element exists: first create a new HTML file and use the input tag to create a text box within the p tag; then set the id attribute of the input tag and create a button; then bind onclick to the button button Click event; finally use the [val()] method to obtain the element you are looking for.

How to determine if an element exists in jquery

Recommendation: "jquery video tutorial"

Jquery method to determine whether an element exists:

1. Create a new html file, named test.html, to explain how jquery determines whether a certain element exists on the page.

How to determine if an element exists in jquery

2. In the test.html file, within the p tag, use the input tag to create a text box for entering the element you want to find.

How to determine if an element exists in jquery

3. In the test.html file, set the id attribute of the input tag to myinput, which is mainly used to obtain the input object below.

How to determine if an element exists in jquery

4. In the test.html file, use the button tag to create a button, bind the onclick click event to the button button, and when the button is clicked, execute seaelem() function.

How to determine if an element exists in jquery

5. In the js tag, create the seaelem() function. Within the function, obtain the input object through the id, use the val() method to obtain the element to be found, and then Obtain the element object through $, use the length attribute to obtain the number of elements on the page, and judge through the if statement to prompt the search result.

How to determine if an element exists in jquery

6. Open the test.html file in the browser, enter the elements to be searched for, and click the button to view the results.

How to determine if an element exists in jquery

Related free learning recommendations: JavaScript (video)

The above is the detailed content of How to determine if an element exists in jquery. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template