• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

insertBefore node was not found

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to create a div and insert it before the end of the body.



Code is like such, newCloud is the new element, and ground is a div that I have on my page. When I test it I get "Node was not found".



HTML like this.

I assume the parent node in is the document?

Thanks
 
Sheriff
Posts: 67756
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where do you inject the newCloud element into the DOM?

In any case, when it comes to DOM manipulation, jQuery is king. I'd advise saving a lot of hair-pulling and adopting jQuery for tasks such as this.
 
Ryan Christiani
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well I would like to try and learn the basics of javascript instead of just relying on jQuery, but yeah, you were saying in another one of my threads to save time and effort using jQuery.

Lets say I want to keep going like this, how exactly do I inject it into the DOM? I assumed that is what the insertBefore method did, you provide it with the new element and the element to have it come before.
 
Bear Bibeault
Sheriff
Posts: 67756
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ryan Christiani wrote:Well I would like to try and learn the basics of javascript instead of just relying on jQuery, but yeah, you were saying in another one of my threads to save time and effort using jQuery.


Yes, it is a good idea to learn the basics -- that way you understand what's going on.

But when push comes to shove, make your life easier with jQuery (or other library of your choice)!

Lets say I want to keep going like this, how exactly do I inject it into the DOM? I assumed that is what the insertBefore method did, you provide it with the new element and the element to have it come before.


What I see missing, is that you are creating an element, but never putting it into the DOM.
 
Marshal
Posts: 28425
102
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ryan Christiani wrote:I assumed that is what the insertBefore method did, you provide it with the new element and the element to have it come before.



You could validate your assumptions by reading some documentation. As a not-very-good Javascript programmer my first reaction to

is "Um, does that insert newCloud before ground or the other way around?"
 
Ryan Christiani
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ahhh appendChild().

some fooling around on lunch at work seems to have helped me there.

Thanks.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic