R
Rajiv Srivastava
Guest
Rajiv Srivastava Asks: Show hidden elements one by one in a div after pressing space jquery
I am having some elements in a div which are set
I am having some elements in a div which are set
display:none
. Now when I press space on my keyboard it should show these elements one by one. Means when I press space first time it should show first hidden element
of the div, then second element
and so on. Please look at my code.
Code:
$(document).keydown(function(e) {
if (e.which == 32) {
$(".main").children().$(":hidden:first").show();
}
});
Code:
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="main">
<p style="display:none">kumar</p>
<a style="display:none">john</a>
<p style="display:none">spiderman</p>
<span style="display:none">Bill</span>
<p style="display:none">Sundar</p>
</div>
SolveForum.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your thoughts here to help others.