Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Old 12-27-2008, 04:09 PM insertBefore problem
pealo86's Avatar
Super Spam Talker

Posts: 850
Name: Matt Pealing
Location: England, north west
Trades: 0
Im using the following code as I want to move a list to be the first element inside a div with the id 'tab'

Code:
var tab = document.getElementById ('tab');
var ul = document.createElement ('ul');
var text1 = document.createTextNode ('Education');
var text2 = document.createTextNode ('Experience');
var text3 = document.createTextNode ('About Me');
var text4 = document.createTextNode ('Show All');
var li1 = document.createElement ('li');
var li2 = document.createElement ('li');
var li3 = document.createElement ('li');
var li4 = document.createElement ('li');
var a1 = document.createElement ('a');
a1.href = '#';

// append list elements and assign id and class
a1.appendChild (text1);
li1.appendChild (a1);
ul.appendChild (li1);
ul.id = 'tabTop';
ul.className = 'navOption';
tab.appendChild (ul);
tab.insertBefore (ul, pAbout1);
But I get this MASSIVE error message on the error console, and I don't have a clue what it's talking about!

Quote:
Error: uncaught exception: [Exception... "Could not convert JavaScript argument arg 1 [nsIDOMHTMLDivElement.insertBefore]" nsresult: "0x80570009 (NS_ERROR_XPC_BAD_CONVERT_JS)" location: "JS frame :: http://www.pealo.local/xampp/mattPea...t/loadAbout.js :: <TOP_LEVEL> :: line 75" data: no]
Any help would be appreciated!
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE
pealo86 is offline
Reply With Quote
View Public Profile Visit pealo86's homepage!
 
 
Register now for full access!
Old 12-27-2008, 04:31 PM Re: insertBefore problem
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
what is the variable pAbout1? I don't see that defined anywhere.
__________________
Join me on
Please login or register to view this content. Registration is FREE
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 12-27-2008, 04:43 PM Re: insertBefore problem
pealo86's Avatar
Super Spam Talker

Posts: 850
Name: Matt Pealing
Location: England, north west
Trades: 0
Oh that was defined earlier on, it's a div element. I only pasted the part of the code that seems to be causing an error.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE
pealo86 is offline
Reply With Quote
View Public Profile Visit pealo86's homepage!
 
Old 12-27-2008, 05:18 PM Re: insertBefore problem
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
It HAS to be an object that exists in the DOM not an ID of an element.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 12-27-2008, 05:55 PM Re: insertBefore problem
pealo86's Avatar
Super Spam Talker

Posts: 850
Name: Matt Pealing
Location: England, north west
Trades: 0
I seeee! How would I refer to the div without the id? at the moment it's declared with

"var pAbout1 = document.getElementById ('pAbout1')"

Thanks.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Last edited by pealo86; 12-27-2008 at 06:28 PM..
pealo86 is offline
Reply With Quote
View Public Profile Visit pealo86's homepage!
 
Old 12-27-2008, 08:20 PM Re: insertBefore problem
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Ok so that is defined elsewhere.
Seeing ALL the code in situ would be a bonus BTW.

The error message means that you are trying to reference a non-existent object (and people complain about MS error messages )
Use a bit of debugging to print object references and states during script execution.
http://www.modtalk.co.uk/article/c-a...another-alert/
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 12-28-2008, 07:44 PM Re: insertBefore problem
pealo86's Avatar
Super Spam Talker

Posts: 850
Name: Matt Pealing
Location: England, north west
Trades: 0
Hmmm errrr... I tried pasting the code on the link you gave me to the bottom of my script and added:

Code:
alert (pAbout1)
Although since nothing new happened I'm guessing that's probably not how it's meant to be used!

Here is all of my code if you'd be so nice as to advise me what's wrong with it . Bear in mind it's the last line of code that seems to be causing the error.

Code:
// create tab for content navigation

// declare divs
var pAbout1 = document.getElementById ('pAbout1');
var pAbout2 = document.getElementById ('pAbout2');
var pAbout3 = document.getElementById ('pAbout3');
    
// edit stylesheet
var styleSheet = document.styleSheets[1];
var pAbout1 = styleSheet.cssRules[20].style;
var pAbout2 = styleSheet.cssRules[22].style;
var pAbout3 = styleSheet.cssRules[23].style;
pAbout2.setProperty ('display', 'none', '');
pAbout3.setProperty ('display', 'none', '');

// functions to show / hide relevant divs
function showAll ()
    {
        pAbout1.setProperty ('display', 'block', '');
        pAbout2.setProperty ('display', 'block', '');
        pAbout3.setProperty ('display', 'block', '');
        return false;
    }

function showAbout1 ()
    {
        pAbout1.setProperty ('display', 'block', '');
        pAbout2.setProperty ('display', 'none', '');
        pAbout3.setProperty ('display', 'none', '');
        return false;
    }

function showAbout2 ()
    {
        pAbout1.setProperty ('display', 'none', '');
        pAbout2.setProperty ('display', 'block', '');
        pAbout3.setProperty ('display', 'none', '');
        return false;
    }

function showAbout3 ()
    {
        pAbout1.setProperty ('display', 'none', '');
        pAbout2.setProperty ('display', 'none', '');
        pAbout3.setProperty ('display', 'block', '');
        return false;
    }

// alter height of div#tab so that it remains the same height for each selected tab
var tabHeight = '440px';
var tab = styleSheet.cssRules[34].style;
tab.setProperty ('height', tabHeight, '');

// create top and bottom tab lists
var tab = document.getElementById ('tab');
var ul = document.createElement ('ul');
var text1 = document.createTextNode ('Education');
var text2 = document.createTextNode ('Experience');
var text3 = document.createTextNode ('About Me');
var text4 = document.createTextNode ('Show All');
var li1 = document.createElement ('li');
var li2 = document.createElement ('li');
var li3 = document.createElement ('li');
var li4 = document.createElement ('li');
var a1 = document.createElement ('a');
a1.href = '#';

// append list elements and assign id and class
a1.appendChild (text1);
li1.appendChild (a1);
ul.appendChild (li1);
ul.id = 'tabTop';
ul.className = 'navOption';
tab.appendChild (ul);
tab.insertBefore (ul, pAbout1);
Thanks!
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Last edited by pealo86; 12-28-2008 at 07:45 PM..
pealo86 is offline
Reply With Quote
View Public Profile Visit pealo86's homepage!
 
Old 12-29-2008, 08:35 AM Re: insertBefore problem
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Need the entire page, HTML code as well. BECAUSE if the code you posted here is in the document head, it will never work! As these declarations;
Code:
var pAbout1 = document.getElementById ('pAbout1');
var pAbout2 = document.getElementById ('pAbout2');
var pAbout3 = document.getElementById ('pAbout3');
will be before the elements exist in the DOM, so they will be empty.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 12-29-2008, 10:10 AM Re: insertBefore problem
pealo86's Avatar
Super Spam Talker

Posts: 850
Name: Matt Pealing
Location: England, north west
Trades: 0
Ahhhh schoolboy error! lol I can't believe how often I make that same mistake, thanks again.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE
pealo86 is offline
Reply With Quote
View Public Profile Visit pealo86's homepage!
 
Old 12-29-2008, 10:56 AM Re: insertBefore problem
pealo86's Avatar
Super Spam Talker

Posts: 850
Name: Matt Pealing
Location: England, north west
Trades: 0
I've also just realised that after that bit of code I had

Code:
var pAbout1 = styleSheet.cssRules[20].style;
So I was basically trying to move a <ul> before a stylesheet rule, don't know what I was thinking when I typed that??
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE
pealo86 is offline
Reply With Quote
View Public Profile Visit pealo86's homepage!
 
Old 12-29-2008, 11:10 AM Re: insertBefore problem
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
I think we've all been there at some time or another
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to insertBefore problem
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.36305 seconds with 12 queries