473,490 Members | 2,592 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

insertBefore generates "node was not found" error

14 New Member
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 8381
Logician
210 New Member
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 Contributor
<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
masterofzen
14 New Member
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
1959
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
511
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
2496
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
1962
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
1640
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
7570
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
3643
Tarantulus
by: Tarantulus | last post by:
if("dept"=='dept'){ document.getElementById('add').style.display='none'; }; <DIV id="add"> <some html here..> </DIV>
8
3232
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
5642
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...
0
6974
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
7146
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7356
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
5448
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,...
1
4878
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
3084
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3074
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
628
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
277
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.