• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

page being replaced by document.write() call

 
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm using jQuery to load a date into a div instead of having the script tucked inside the div tags themselves. I gave the div and id of "date" and then in the .ready() I used this line of code...


obviously getDate() is the name of the externally defined javascript function. But I get an error that says "Node cannot inserted at this spot in the hierarchy".

When I try to load the page in the browser all it does is show the date in black text on a white page. I have a lot of divs used for formatting on that page and there should be much more going on. Just wondering if anyone knows what happening?

Thanks
Bryce
[ January 17, 2008: Message edited by: Bear Bibeault ]
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Its hard to tell without seeing your getDate() function. What is it returning? No code == no help.
 
Bryce Martin
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm returning a string.
After I posted I looked at the function and noticed it was doing a document.write() at the end. So I changed it to return a string and it has the same problem.


Here is the function...



I hope this helps.

[ January 17, 2008: Message edited by: Bryce Martin ]
[ January 17, 2008: Message edited by: Bryce Martin ]
 
Sheriff
Posts: 67746
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
Never do a document.write() except in inline code (in fact, I recommend not doing it there either). All that will do is to replace your current document with the new one you just wrote. This is what is causing your blank page. Nothing to do with jQuery.

I've amended the topic title accordingly.
[ January 17, 2008: Message edited by: Bear Bibeault ]
 
Bear Bibeault
Sheriff
Posts: 67746
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
It also looks like you are using appendTo() incorrectly. If you are trying to append something to the element in the matched set, you should be using append().

appendTo() is intended to take (usually new) markup and append it to the elements defined by the passed selector. For example:This creates new span and appends it to the body.

As opposed to which appends the text "whatever" to the body.

See the difference?
[ January 17, 2008: Message edited by: Bear Bibeault ]
 
Bryce Martin
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey guys. After I pulled out the document.write and then replaced it to return a string. I replaced appendTo with append and all is working well. I had an old version of the external javascript file in the cache. I cleared it out and *tada*. Works like a charm and I've made my code better Thanks guys.
 
Bear Bibeault
Sheriff
Posts: 67746
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
Too cool!
 
What are you saying? I thought you said that Santa gave you that. And this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic