jquery - Hiding and displaying all divs on keyboard press -


i not experienced jquery came here hoping answer. problem having how hide of divs on webpage, when clicking keyboard button.

i know basic code hiding , showing div be:

$(document).ready(function() {     $("div").hide();       $("div").show(); }); 

what don't know if there easier way hide every div on webpage rather having hundred $("div").hide(); statements. not sure how monitor click on keyboard , hide , show various divs.

thanks!

at simplest, you'll need listen keypress event (or keyup or keydown events) and, if particular key used respond event:

$(document).keypress(function(e){     var key = e.which;     if (key == 116) {         // if user pressed 't' (for 'toggle'):         $('div').toggle();     } }); 

simple js fiddle demo.

references:


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

qt - Errors in generated MOC files for QT5 from cmake -