We help IT Professionals succeed at work.
Get Started

jQuery hiding/showing elements

gplana
gplana asked
on
602 Views
Last Modified: 2012-08-20
Hi.

I have this code:

	var to_hide = jQuery(".prev_disableNextFields").parent();
	jQuery("<div id='prev_show_hide_fields'></div>").insertAfter(to_hide);
	to_hide = jQuery(to_hide).next().next();
	for(a=0; a<24; a=a+1){
			jQuery("#prev_show_hide_fields").append(to_hide);
			to_hide = jQuery(to_hide).parent().next();
	}

Open in new window


which is working ok to hide 8 controls I have in a form (every control has 3 DOM elements, so 8x3 = 24). However, I would like to hide all these 8 elements except the third, so I tryied something like this:

	var to_hide = jQuery(".prev_disableNextFields").parent();
	jQuery("<div id='prev_show_hide_fields'></div>").insertAfter(to_hide);
	to_hide = jQuery(to_hide).next().next();
	for(a=0; a<6; a=a+1){
			jQuery("#prev_show_hide_fields").append(to_hide);
			to_hide = jQuery(to_hide).parent().next();
	}
	for(a=0; a<3; a=a+1){
			to_hide = jQuery(to_hide).parent().next();
	}
	for(a=0; a<15; a=a+1){
			jQuery("#prev_show_hide_fields").append(to_hide);
			to_hide = jQuery(to_hide).parent().next();
	}

Open in new window


But this doesn't work (it just hides first 2 elements, instead of all elements except third). What I'm doing wrong ?

Thank you.
Comment
Watch Question
Information Systems Manager
CERTIFIED EXPERT
Top Expert 2012
Commented:
This problem has been solved!
Unlock 1 Answer and 18 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE