/    Sign up×
Community /Pin to ProfileBookmark

‘tagName’ is null or not an object

new to javascripting, i have got a peice of code, which keeps popping up with an error when its run in internet explorer just at the bottom. with the error message reading

‘tagName’ is null or not an object

then relates to the this bit of code i belive
[INDENT] if(!obj.tagName.match(/div/i)) return 0;[/INDENT]

the code still runs fine just comes up with the error message at the bottom and its just anyoing!

any thoughts anyone??

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@aj_nscNov 17.2008 — Is this run on an (X)HTML page or XML document? Try nodeName instead of tagName.
Copy linkTweet thisAlerts:
@sheep_childauthorNov 17.2008 — yea cool thats seams to have sorted it, what is the differnce between nodeName and tagName??

though i still seam to getting an error but on a differnt line


obj.style.height = height + 'px';

saying invalid argument can you help with that one??
Copy linkTweet thisAlerts:
@sheep_childauthorNov 17.2008 — in fact i will just post all the code and see if you can figure it out???

slideSpeed = 20;

function expandMenu()

{

if(!document.getElementsByTagName) return;

slider = new Array();

var divs = document.getElementsByTagName('div');

for(var x=0; x<divs.length; x++)

{

divs[x].originalHeight = divs[x].offsetHeight;

if(divs[x].className == 'coursemaininfo') divs[x].speed = -1;

if(divs[x].className == 'button') divs[x].onclick = function() { DropDown(this); };

}

for(var x=0; x<divs.length; x++)

{

if(divs[x].className != 'coursemaininfo') continue;

divs[x].style.height = '1px';

divs[x].style.display = 'none';

}

}

function DropDown(obj)

{

obj.className = (obj.className == 'button')?'pressedButton':'button';

while(obj.nextSibling && (obj.className != 'coursemaininfo')) obj = obj.nextSibling;

obj.speed = -1 * obj.speed;

if(obj.slideTimer) return; //Already moving

var x = slider.length;

slider[x] = obj;

slide(x);

}


function slide(x)

{

var obj = slider[x];

if(obj.style.display != 'block') obj.style.display = 'block';

var height = obj.offsetHeight + obj.speed * slideSpeed;

var targetHeight = getChildrensHeights(obj);

if(height > targetHeight)

{

obj.style.height = targetHeight + 'px';

obj.slideTimer = false;

resizeParents(obj, 0);

return;

}

if(height <= 1)

{

obj.style.height = '1px';

obj.style.display = 'none';

obj.slideTimer = false;

resizeParents(obj, 0);

return;

}

obj.style.height = height + 'px';

obj.slideTimer = setTimeout('slide(' + x + ');', 10);

resizeParents(obj, targetHeight - height);

}

function getChildrensHeights(obj)

{

if(!obj.firstChild) return 0;

if(!obj.nodeName.match(/div/i)) return 0; <====================== where i changed it to nodeName

var height = 0;

tmp = obj;

obj = obj.firstChild;

do height += getChildrensHeights(obj);

while(obj == obj.nextSibling);

if(height === 0) height = tmp.offsetHeight;

return height;

}

function resizeParents(obj, diff)

{

if(obj.className == 'menuBox') return;

obj = obj.parentNode;

height = getChildrensHeights(obj) - diff;

obj.style.height = height + 'px';

resizeParents(obj,diff);

}
Copy linkTweet thisAlerts:
@aj_nscNov 17.2008 — I've actually never seen tagName used before so I had to look it up, and apparently (according to w3schools) it's good for JS working with XML documents, although I'm not 100&#37; sure on how it's supposed to be used/able to be used.

As for the trouble with your second issue all I can figure is that there is something wrong with your reference to obj at that point. alert() out what obj actually is (by using something like alert(obj.nodeName) so you can see what object you are trying to change the height of when your code breaks, maybe you'll come up with something when you try this.

It might be a little more helpful if you tell is what line that error comes out on, as well, because there is more than one place in your code where that line exists.
×

Success!

Help @sheep_child spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...