473,467 Members | 1,596 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

recursive function always return null

Hi,

Here's the function:

function getParentElementByTagName(child, TagName){
var cn;
if (child.parentElement){
cn = child.parentElement;
if (child.parentElement.tagName == TagName){
return cn;
}else{
getParentElementByTagName(child.parentElement, TagName);
}
}
}

although it finds the element, the function returns null ( on the line
'return cn', cn is not null though). Is my algorithm wrong ?

thanks

Aug 15 '06 #1
4 2964


sa*************@googlemail.com wrote:

function getParentElementByTagName(child, TagName){
var cn;
if (child.parentElement){
W3C DOM knows a property parentNode but not a property named
parentElement (which is IE DOM). IE 5 and later have parentNode too so
you probably want to use parentNode and not parentElement.
As for the problem, which browser does that occur with?

--

Martin Honnen
http://JavaScript.FAQTs.com/
Aug 15 '06 #2
Hi,
I'm using IE 6 and Firefox. I've replaced parentElement with parentNode
but still returned undefined, although in the function I can see it
finds the right node :(
something must be wrong with the recursion.

Aug 15 '06 #3


sa*************@googlemail.com wrote:

I'm using IE 6 and Firefox. I've replaced parentElement with parentNode
but still returned undefined, although in the function I can see it
finds the right node :(
something must be wrong with the recursion.
You need to use return on the recursive call
getParentElementByTagName(child.parentElement, TagName);
return getParentElementByTagName(child.parentNode, TagName);

--

Martin Honnen
http://JavaScript.FAQTs.com/
Aug 15 '06 #4
Of course ! I'm so stupid...:(

Thank you !

Aug 15 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: | last post by:
OK: Purpose: Using user's input and 3 recursive functions, construct an hour glass figure. Main can only have user input, loops and function calls. Recursive function 1 takes input and displays...
3
by: Dimitri Furman | last post by:
SQL Server 2000 SP3. Is it possible for the @@ROWCOUNT function to return NULL after a statement? I am troubleshooting a relatively large stored procedure with multiple SELECT statements and a...
4
by: Nicolas Vigier | last post by:
Hello, I have in my python script a function that look like this : def my_function(arg1, arg2, opt1=0, opt2=1, opt3=42): if type(arg1) is ListType: for a in arg1: my_function(a, arg2,...
1
by: plmanikandan | last post by:
Hi, I am using LookupPrivilegeValue to check whether SE_TCB_NAME privilege exists for the user or not in windows 2000 .The value returned from LookupPrivilegeValue function is always true.i...
6
by: Uwe Grawert | last post by:
I have the following recursive function: string find_value_by_key (xmlDocPtr doc, xmlNodePtr root_node, const string& key) { while(root_node != NULL) { if(! xmlStrcmp( root_node->name,...
2
by: r3ap3r | last post by:
I am using the following recursive function for an assigment string GetString(char numbers, int curNum){ string returnString = ""; int temp; if (numbers != '\0'){ for (int i = 0; i <=2;...
2
by: mlevit | last post by:
Hi, I've written my own JavaScript and used a couple of codes to set and get cookies from the net I found. When I set the cookie I can see it in my browser, it is set with the right value and...
2
by: michaelscript | last post by:
hi ... here is a recursion , suppose it will return a value and but,,,when the function returned with a value ,and a var incept it, still it is null or undefined.. the code here: function...
1
by: Jan Obrestad | last post by:
I'm developing an application that uses a webservice. It was working fine a few month ago, but going back to the project after a couple of months on other projects, the code is suddenly not...
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
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...
1
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
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.