Home > Web Front-end > JS Tutorial > body text

How to determine whether an element is clicked in jquery

王林
Release: 2020-11-30 15:01:43
Original
4386 people have browsed it

Jquery method to determine whether an element is clicked: after the click event occurs, change the value of the flag bit and record the click status, thereby achieving the purpose of determining whether the element is clicked, such as [$('#test') .click(function(){isClick = true;});].

How to determine whether an element is clicked in jquery

The operating environment of this tutorial: windows7 system, jquery3.2.1 version. This method is suitable for all brands of computers.

Jquery method to determine whether an element is clicked:

(Learning video sharing: javascript video tutorial)

Thinking:

After the click event occurs, the value of the flag bit is changed and the click status is recorded, thereby achieving the purpose of determining whether the element has been clicked.

1 function(){
2 var isClick = false;
3 $('#test').click(function(){isClick = true;});
4 $('#show').click(function(){alert(isClick);})
5 }
Copy after login

Add and delete classes: $('#id').addClass(), $('#id').removeClass()

Get the setting element value: $('.class' ).text(), $('#id').html(), $('.class').val()

Add attributes or modify attribute values: $('#id'). attr({'style':'display:none'})

toggle()

toggle() method switches the visible state of an element. Hides the selected elements if they are visible, and shows them if the selected elements are hidden.

Grammar:

$(selector).toggle(speed,callback,switch)
Copy after login

The parameters are as follows:

How to determine whether an element is clicked in jquery

##Related recommendations:

js tutorial

The above is the detailed content of How to determine whether an element is clicked 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