Home  >  Article  >  Web Front-end  >  How to determine whether an element is clicked in jquery

How to determine whether an element is clicked in jquery

王林
王林Original
2020-11-24 11:32:394373browse

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 }

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)

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!

Statement:
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

Related articles

See more