473,396 Members | 1,917 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

remove siblings after current

107 100+
Hi Guys,

Ive got a menu that dynamically creates <select> drop down boxes for categories and sub categories etc.

When a dropdown is changed I want to remove all susequent siblings (all <select>'s) from the current div.

Heres the code i have....

Expand|Select|Wrap|Line Numbers
  1.  
  2. function removeSiblingsAfterl(dd){
  3.  
  4.     //remove siblings after dd
  5.  
  6.     divCatsel = document.getElementById('catselect');
  7.     siblingNode = dd.nextSibling;
  8.  
  9.     while (siblingNode.nextSibling) {
  10.         divCatsel.removeChild(siblingNode);
  11.         siblingNode = siblingNode.nextSibling;    
  12.     }
  13.  
  14.     //add new select box in place....
  15.  
  16. }
  17.  
"dd" is the last used select box, using onchange="removeSiblingsAfter(this)"

So basically you will select an option from one DD box and all the ones after will be removed and then replaced by a new one.

I just cant seem to get it removing all the sibling nodes after the current one correctly..

Can anyone help?

thanks

Andy
May 18 '08 #1
9 8989
Logician
210 100+
[quote=theS70RM]
Expand|Select|Wrap|Line Numbers
  1.  
  2.     while (siblingNode.nextSibling) {
  3.         divCatsel.removeChild(siblingNode);
  4.         siblingNode = siblingNode.nextSibling;    
  5.  
If you've just removed siblingNode, how can you get its next sibling?
Try this:
Expand|Select|Wrap|Line Numbers
  1. function removeSiblingsAfterl(dd)
  2. {
  3.   var ns;
  4.    while (ns=dd.nextSibling) 
  5.      dd.parentNode.removeChild(ns);    
  6. }
  7.  
May 18 '08 #2
hsriat
1,654 Expert 1GB
Try this:
Expand|Select|Wrap|Line Numbers
  1. function removeSiblingsAfterl(dd)
  2. {
  3.   var ns;
  4.    while (ns=dd.nextSibling) 
  5.      dd.parentNode.removeChild(ns);    
  6. }
  7.  
Too right, but may give a small warning: Mistyped == as =


Expand|Select|Wrap|Line Numbers
  1.  
  2. function removeSiblingsAfterl(dd){
  3.     while (dd.nextSibling) 
  4.     dd.parentNode.removeChild(dd.nextSibling);
  5.  
  6. }
  7.  
May 18 '08 #3
Logician
210 100+
Too right, but may give a small warning: Mistyped == as =
No - assignment was intended.
May 18 '08 #4
hsriat
1,654 Expert 1GB
No - assignment was intended.
Sure it was needed.. I'm not saying it wasn't.
May 18 '08 #5
mrhoo
428 256MB
To avoid the warning you can write assignment in conditionals like-

while ((ns=dd.nextSibling)!=null){
May 18 '08 #6
hsriat
1,654 Expert 1GB
To avoid the warning you can write assignment in conditionals like-

while ((ns=dd.nextSibling)!=null){
That's a good solution.
May 19 '08 #7
theS70RM
107 100+
That's a good solution.
thanks chaps, ill give that a try


Andy
May 20 '08 #8
theS70RM
107 100+
Worked a treat, thanks very much!
May 21 '08 #9
hsriat
1,654 Expert 1GB
Worked a treat, thanks very much!
That's fine :)

Glad to know you got it working.
May 21 '08 #10

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

Similar topics

2
by: Ian Gibbs | last post by:
Dear all, I'd like to know in the following XML, when I am looping through the server elements, how many of the previous servers had ldap-role values of YES or MASTER. <install-config>...
8
by: Joseph | last post by:
I have a textBox that people writes stories in it. They can use for format. I have Aspell installed on the server, so people can make correction to their text. Sometimes, they forget to add a...
1
by: blabla120 | last post by:
Hi! I have the following xml structure: <DBCommands> <Customer/> <Contract/> <--- I am here <Contract/> </DBCommands>
2
by: Gabe Moothart | last post by:
Hi, I need some help figuring out how to do something in xslt. I have an xml document with a list of items. Each item in turn can have a list of options, like so: <item> <stuff>Item 1...
6
by: tshad | last post by:
Is there a reason to use session.remove over session.contents.remove? Don't they both remove the key and data from the contents collection? I assume that session(x) = nothing does essentially...
7
by: Susan Mackay | last post by:
I have a data table that is connected to a database table with a data adapter in the 'standard' manner. However I want to be able to remove selected rows from the data table (i.e. no longer...
2
by: Nathan Sokalski | last post by:
I have an application that is using Session state. On one page, I use the Session.Add() method to create the Key/Value pair for the first time. I am then sent to another page using...
2
by: =?Utf-8?B?R3JlZw==?= | last post by:
I have the following code the dynamically adds a specific number of controls. for x as integer = 1 to 10 Dim btn as Windows.Forms.Button = New Windows.Forms.Button btn.Name = "btn" & x btn.Text...
5
by: Telz | last post by:
Hello, I am a begginer to JavaScript (as you can probably see) currently working on a web page to display equipment info when "MouseOver"-ing a picture of the equipment. The info is stored in an...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.