javascript - Show & Hide an element after click -


what want simple. when click image, want message appear. afterwards, when click again want disappear. have problems iplementing due lack of jquery knowledge. appreciate following code, other implementations. know can class="hidden" , have jquery add/remove oh well.

this i'm trying work with.

<!doctype html> <html> <head> <script>  function greet(){     = document.getelementbyid('here');      if (a.trim().length==0){         a.innerhtml = 'message!';     }         else{         a.innerhtml = '';      }  </script> </head> <body>  <img src="http://www.clker.com/cliparts/k/9/m/i/m/8/on-button-small-th.png" alt="alt" onclick="greet()"/> <p id='here'></p>  </body> </html> 

edit: seems should use a.value, must doing else wrong too.

if using jquery simple; use javascript (don't forget link jquery main library - google cdn that). use toggle function:

function greet() {     $('#here').toggle(); } 

also better register onclick through jquery rather html (for examplesee this question). whole page instead :

<!doctype html> <html> <head>  <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <script> $( document).ready(function() {     $("#greet").click(         function () {              $('#here').toggle();         }     );      $("#here").hide();     } </script> </head> <body>  <img id="greet" src="http://www.clker.com/cliparts/k/9/m/i/m/8/on-button-small-th.png" alt="alt"/> <p id='here'><!--message should here--></p>  </body> </html> 

working example in jsfiddle.


Comments

Popular posts from this blog

c - ALSA programming: how to stop immediately -

c++ - How to add Crypto++ library to Qt project -