Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

EricBrian

macrumors 6502a
Original poster
Jul 30, 2005
656
7
So, I have a css class selector:

.obj_ind {display:inline}

with many divs that have have class="obj_ind".

I plan on providing a button that lets users hide all thoses divs with where class="obj_ind". So, when the users click hide Obj Inds, I need to change the display:none in the .obj_ind class selector.

Anybody know the js to do this?

Thanks
Eric
 

angelwatt

Moderator emeritus
Aug 16, 2005
7,852
9
USA
Here's a quickie function that'll get the job done.
PHP:
function HideDivs()
{
  var divs = document.getElementsByTagName('div');
  for (var a=divs.length-1; a>=0; --a) {
    if (divs[a].className == 'obj_ind') {
      divs[a].style.display == 'none';
    }
  }
}
 

chaosdude78

macrumors newbie
Mar 21, 2008
14
0
There are numerous ways to do this, the easiest of which would probably be if you are using jQuery.

first, download and link the jQuery library to the page (get it at jQuery.com)

then, try something like this:
Code:
$(document).ready(function(){
    $("#buttonID").click(function(){
        $(".classToHide").css("display","none");

    });
});
 

nightelf

macrumors 6502
Mar 25, 2003
272
1
There are numerous ways to do this, the easiest of which would probably be if you are using jQuery.

first, download and link the jQuery library to the page (get it at jQuery.com)

then, try something like this:
Code:
$(document).ready(function(){
    $("#buttonID").click(function(){
        $(".classToHide").css("display","none");

    });
});

You could also have:

Code:
$(document).ready(function(){
    $("#buttonID").click(function(){
        $(".classToHide").hide();

    });
});

If you want a nice effect you could replace hide() with fadeOut().
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.