Abizern Abizern - 5 months ago 8
jQuery Question

how can i hide text after any click on button in jquery

How can I hide text after two click on text in jQuery?

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("p").click(function(){
$(this).hide("slow");
});
});
</script>
</head>
<body>
<p>If you click on me, I will disappear.</p>
</body>
</html>

Answer

Code for double click event.

$("p").dblclick(function(){
    $(this).hide("slow");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<p>If you click on me, I will disappear.</p>

Code for second click event.

$("p").click(function(){
    if($(this).hasClass('one'))
        $(this).hide('slow');
    else
        $(this).addClass("one");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<p>If you click on me, I will disappear.</p>

Comments