-2

Possible Duplicate:
javascript hide/show element
How to hide or show div on click in HTML

I have a blog. On the right sidebar, there are several gadgets, but I want to make a button that will hide a specific gadget or div element, I just need an idea, I will style the div elements and class myself.

Community
  • 1
  • 1
Deepak Kamat
  • 1,880
  • 4
  • 23
  • 38

3 Answers3

0
<div onclick="document.getElementById('tohide').style.visibility = 'hidden';">
gcochard
  • 11,408
  • 1
  • 26
  • 41
0

Here's a simple example http://jsfiddle.net/qRwDr/

just explain me in detail how do you want it to work, i'll help you out.

Salil Momin
  • 361
  • 3
  • 11
-1

You can use jquery to achieve ur requirement,

$('button').on('click', function(){
    // perform something for eg :
    $('div').hide();
});

You can visit www.jquery.com for more details.

Shreedhar
  • 5,502
  • 3
  • 22
  • 27
  • 1
    Or not. It is too simple to need jQuery if not already used elsewhere - and "live" is deprecated. It is now "on" and you forgot the quotes – mplungjan May 13 '12 at 05:13
  • PS: On static pages it is .click(...) and not .live or .on which is appropriate – mplungjan May 13 '12 at 05:27
  • Forgot quotes? Quotes for what? What he has will will work fine... Except for changing `live` to `on`. Also, that is not always right. `.click` gets translated to `.on` anyway. You need a bit more code to make `.on` to work on a dynamic page. – LeeR May 13 '12 at 05:28
  • There were no quotes around the 'click' when I commented - and live is still deprecated – mplungjan May 13 '12 at 05:32
  • now that code works fine. you can check, as i forgot to add quotes for click. – Shreedhar May 13 '12 at 05:34
  • use on or click instead of live, please – mplungjan May 13 '12 at 07:30
  • @mplungjan, please open stackoverflow website and run the below code in console $('p').live('click', function(){ $('img').hide(); }); finally click on first p tag i,e. click on your question, and check whether it will or not, you can use .live instead of .on . please run the code which i posted here before commenting it as wrong. – Shreedhar May 13 '12 at 15:17
  • 1
    It is not wrong in principle. It will still work. Just never use deprecated calls, especially not as answers to inexperienced javascripters. Or do you not know what [deprecated](http://en.wikipedia.org/wiki/Deprecation) means? _As of jQuery 1.7, the .live() method is deprecated. Use .on() to attach event handlers. Users of older versions of jQuery should use .delegate() in preference to .live()._ And in my opinion it is clearer to use [.click(...)](http://api.jquery.com/click/) in this particular case – mplungjan May 13 '12 at 15:28
  • Yeah if u knew this much info why did u asked for idea? I gave only idea mate, here u ll get an idea to solve ur problem not the solution. Yeah I do agree ur point but I just said you can use some kinda code as I posted above. – Shreedhar May 13 '12 at 16:38
  • $('p').on('click', function() { $('img').hide(); }); i agree your point mate :) – Shreedhar May 13 '12 at 16:45