472,949 Members | 1,973 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

insertBefore generates "node was not found" error

I've been playing around with this for a while. I bet the answer is pretty obvious, but I'm just not seeing it. I'm also reasonably certain I've run into this problem before.

I'm trying to dynamically insert a few nodes into a webpage using insertBefore. Here's the HTML in question. (Yes, I know the HTML is terrible, but I didn't write it and can't edit it, which is why I have to insert things through the DOM instead. Long story.)

[HTML]<div id='paginaMinion' class='mod_profile_display_bottom mod_profile_display module'>
<div class="container">
<div class="title_container">
<h3 class="title">
<span class="title_span">
<a href="http://mipagina.univision.com/janiiita" class="title_span_link">
<div class="title_span_div"></div>
</a>
</span>
<div class="spreader"></div>
</h3>

<div class="spreader"></div>
</div>

<ul>
<a name="massobremi"></a>
<div id="lower_layout">
</div>
<div class="spreader"></div>
<div id="lower_layout2">
</div>
</ul>

<div class="spreader"></div>
</div>
</div>[/HTML]

Now, here's the JavaScript I've inserted after the HTML appears in the document:

Expand|Select|Wrap|Line Numbers
  1. var msm = document.getElementById('paginaMinion');
  2. var msmULArr = msm.getElementsByTagName('ul');
  3. var msmUL = msmULArr[0];
  4. var coverDiv = document.createElement('div');
  5. var coverAnchor = document.createElement('a');
  6. coverAnchor.setAttribute('href','http://www.example.com/');
  7. var coverAnchorText = document.createTextNode('Example 1');
  8. coverAnchor.appendChild(coverAnchorText);
  9. var coverText = document.createTextNode('Example 2');
  10. coverDiv.id = 'coverdiv';
  11. var commonBR = document.createElement('br');
  12. coverDiv.appendChild(coverText);
  13. coverDiv.appendChild(commonBR);
  14. coverDiv.appendChild(coverAnchor);
  15.  
  16. msm.insertBefore(coverDiv, msmUL);
The insertBefore causes a "node was not found" error and nothing is inserted into the document. Does anyone have any idea why?
Jun 18 '08 #1
3 8339
Logician
210 100+
The insertBefore causes a "node was not found" error and nothing is inserted into the document. Does anyone have any idea why?
msm is not the immediate parent of msmUL. Try
Expand|Select|Wrap|Line Numbers
  1. msmUL.parentNode.insertBefore(coverDiv, msmUL)
Jun 19 '08 #2
mrhoo
428 256MB
<h3>
<span>
<a>
<div></div>
</a>
</span>
<div></div>
</h3>

What is a browser to do- an <h3> is not supposed to contain block elements,
and neither are <span> or <a> elements.

Here is a div inside an <a> inside a <span> inside an <h3>, which also has another <div> after the <a>.
I'm surprised your list isn't in there too. But how is the browser supposed to assemble a DOM view of that?
Jun 19 '08 #3
I had no idea you had to reference the immediate parent -- I thought any parent would do. The parentNode solution was a great idea and worked like a charm -- thanks!

I have to work with some pretty badly formed HTML on a day-to-day basis, and a substantial part of my job is making it do things it can't or isn't supposed to with JavaScript. Browsers will always assemble a DOM view of whatever they see -- it just may not be anything remotely like what you'd expect!
Jun 19 '08 #4

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

Similar topics

0
by: Adil Akram | last post by:
I'm using IIS 5.0 Win2K (SP3). IIS sometime reports ASP 0126 "Include file not found" error on several .asp pages. 've checked my ASP coding its alright and works lot of time but some time it...
0
by: Ari Royce Hidayat | last post by:
Dear ALL, Is there some one ever faces this problem? And fix it? The scenario is: There's an html page that hosts a .net object (using object tag), and this page opens the second html page...
6
by: Stan | last post by:
There are over 200 people using the intranent web site and only one computer has a very strange problem. The web page has a button. When the button is clicked, the form is posted back and...
4
by: mattsthompson | last post by:
Im writing a DLL that extends IHttpHandler to intercept requests for a certain file extension and deliver watermarked images. I'm using LeadTools' .NET framework for the image manipulation and it...
1
by: Casper Stendal | last post by:
Is it some how possible to handle a "directory not found" error through ASP.NET (or ASP), without having to make speciel a setup for the application in IIS, when it comes from an URL without...
2
by: johkar | last post by:
Why does if(win==null || win.closed) return true after one PDF is open. Something very wierd going on with IE 6. I also get a member not found error if a child window is already open. This script...
6
Tarantulus
by: Tarantulus | last post by:
if("dept"=='dept'){ document.getElementById('add').style.display='none'; }; <DIV id="add"> <some html here..> </DIV>
8
by: webgenius | last post by:
Whenever I click the SUBMIT button in my HTML page, I get the "Object not found!" error. It was working fine yesterday. This error started to occur after I installed Codelobster and made some changes...
3
maliksleo
by: maliksleo | last post by:
hi all i m having this "The resource cannot be found." error. I applied the url rewriting on my project every page is being browsed very well but i am getting the above error an some pages i dont...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

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.