473,766 Members | 2,020 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Hide all classes called container, but the first one?

4 New Member
Hi,

I have this following code in my html page

Expand|Select|Wrap|Line Numbers
  1. <div class="container">
  2.     <div ...
  3. </div>
  4. <div class="container">
  5.     <div ...
  6. </div>
  7. ... and so on
I want to be able to, through some Javascript, hide all div with the class "container" but the first one...

is it possible?
Jan 12 '07 #1
4 1729
acoder
16,027 Recognized Expert Moderator MVP
Do you specifically need that for any number of divs, the first one remains visible while the rest are hidden? If not, set an id for each div like so
Expand|Select|Wrap|Line Numbers
  1. <div id="idname" ...>
then use the following to hide a div
Expand|Select|Wrap|Line Numbers
  1. document.getElementById("idname").style.visibility = 'hidden';
Jan 12 '07 #2
Romulo NF
54 New Member
well.. i hope thats what you looking for:

Expand|Select|Wrap|Line Numbers
  1.  
  2. var divs = document.getElementsByTagName("DIV");
  3.  
  4. for (x=1; x<divs.length; x++) {
  5. if (divs[x].className=="container) {
  6. divs[x].style.display = "none";
  7. }
  8. }
  9.  
the loop is starting with 1 because 0 is your first div

important: that code is assuming ALL divs in your page are containers
for example if you have 5 divs.. and only 3 are containers... and the other 2 are before em in the html structure, the code will hide all the containers!
Jan 12 '07 #3
Romulo NF
54 New Member
Expand|Select|Wrap|Line Numbers
  1. <script>
  2.  
  3. var divs = document.getElementsByTagName("DIV");
  4. var number = 1
  5.  
  6.     for (x=0; x<divs.length; x++) {
  7.         if (divs[x].className=="container") {
  8.         divs[x].order=number
  9.             if (number>1) {
  10.             divs[x].style.display="none";
  11.             }        
  12.         number = number+1
  13.         }
  14.     }
  15.  
  16. </script>
  17.  
use something like that so you dont have to worry if you have more divs with others or without classes in the same page!
Jan 12 '07 #4
municipal
4 New Member
thanks for the reply guys, I really appreciate it.

Romulo NF: I was almost there, but didn't know I could do this:

Expand|Select|Wrap|Line Numbers
  1. divs[x].className=="container"
now I know and it should all work out

thanks again! :)
Jan 12 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

9
1908
by: Pierre Barbier de Reuille | last post by:
Ok, I first want to stress that I looked through the newsgroups archives (on Google) for an answer to my question, but I didn't find it. It's about the interface of the set classes as defined in the PEP 218. I don't understand why the sets has an interface of mapping object without associated value and not an interface of sequence ? For me, sets are first sequences. I use set where lists are inefficient or inadapted, for example when I...
10
2565
by: Bjorn | last post by:
I'm using interfaces in C++ by declaring classes with only pure virtual methods. If then someone wants to implement the interface they needs to inherit from the class. If the implementing class forgets to implement some method I normally get a compile error(if the class is created in some way of course). When using the Visual Studio 6 compiler however, it does not generate a compile error in this case: - I have a implementing class A...
3
1676
by: Ed | last post by:
Hi, I have a WorkUnit class. I will pass a reference to a group of these WorkUnits to other classes in my application. I have chosen to use a vector to hold pointers to these WorkUnits for now. However, I think that I should hide the fact that it's a vector in case I want to switch to another container class at a later date. I don't want every class that needs to use the group of WorkUnits to be too tightly bound to the details of the...
4
8009
by: jerryyang_la1 | last post by:
I've found this script that allows be to hide/show form elements.. <script language="JavaScript"><!-- var toggle = true; function show(object) { if (document.layers && document.layers) document.layers.visibility = 'visible'; else if (document.all) { document.all.style.visibility = 'visible';
1
16757
by: asilverpeach | last post by:
Hey Guys! Found some great scripts here on this topic but have to make to changes to the code that I can't seem to figure out. First, In the following code clicking on the headers shows the div information. I want a nested show hide element though. So when you click on "Do you have carpets to be cleaned?" Small Rooms & Medium Rooms appears (that I got working) But Then when you click on Small rooms or medium rooms i want the three lines...
2
1706
by: Chicken15 | last post by:
Hi Group. First of all I'm sorry for asking (maybe) such easy questions. But I'm quite stuck now and couldn't come up with a solution by using my C# book or googling. So it would be nice if someone could help me out. Now first of all I want to describe the setting in a simpler (I'm using Visual Studio 2005): Form: One comboBox (dropdown list) and 2 buttons. Classes: Class1 with a function do() which plainly returns a string.
2
35620
weaknessforcats
by: weaknessforcats | last post by:
Handle Classes Handle classes, also called Envelope or Cheshire Cat classes, are part of the Bridge design pattern. The objective of the Bridge pattern is to separate the abstraction from the implementation so the two can vary independently. Handle classes usually contain a pointer to the object implementation. The Handle object is used rather than the implemented object. This leaves the implemented object free to change without affecting...
15
3809
by: worked | last post by:
I have a script that hides / shows form elements, and wrapped in a tab script (tab navigation). When the code is duplicated (per tab content), the hide / show function works for the first tab but breaks in each subsequent tab. Why? Help appreciated! Example: http://geocities.com/edmurphy21/ hide / show script: <script type="text/javascript"> function showHide() { var idx = this.id.split('-'); var sp =...
0
10168
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10008
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9959
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9837
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5279
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3929
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.