I want to hide an element after it is first clicked (using jQuery), so that user can’t see and click the element after that.
How can I do that?
Thanks.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Very simply:
"selector"above would be any valid jQuery selector (e.g.".click-to-hide"to make all elements with classclick-to-hidehave this behavior). Hiding the element is done using the jQueryhidemethod (there is alsoshowif you want to make the elements visible again later).If you do not intend to do anything at all with the elements after they are hidden for the first time, you might also want to consider
removeinstead ofhide.Update: To do something on the second click, you need to remember when a click has already been made on an element. If it’s not going to get more complicated than that, you could use a class for this purpose:
If you want to count the clicks, you can use the
datafunction to store the amount of clicks the element has received: