Jump to content

innerHTML + XHTML = bug


KevinM1

Recommended Posts

I just found out (the hard way) that using innerHTML with XHTML produces a bug.  While whatever one puts into innerHTML will appear on the screen, it won't be placed within the source code.  This is a bit of a problem for me because my script (which is in an external file) relies on CSS (which is in another external file) classes for formatting.  Since the code isn't really inserted into the XHTML, the script doesn't use the classes of the linked CSS file.

I know there are createElement and appendChild methods.  But I need to be able to write within the elements my script creates as well.  Is there a way to do something like a document.write within my body element?  Is write available for an element retrieved with a getElementByID?
Link to comment
Share on other sites

I just tried it without any XHTML references in the head and it's still doing the same thing.  innerHTML should show whatever I have in it in the source, correct?  Because right now it's only showing the empty body element that I used innerHTML to fill.

EDIT: I have a copy of my XHTML at http://www.nightslyr.com/calendar/calendar2.html
The JavaScript can be found at http://www.nightslyr.com/calendar/calendar.js
The CSS (which isn't working at this point because of my error) is at http://www.nightslyr.com/calendar/calendar.css
Link to comment
Share on other sites

[quote author=fenway link=topic=111769.msg453391#msg453391 date=1161123472]
What do you mean by "source code"? Where isn't it appearing?
[/quote]

What I mean is this:
I have a very simple XHTML page that literally only consists of an empty body element (well, there's the normal XHTML Strict head element goodies...).

My script outputs the calendar, which are nested tables, as the innerHTML of the body element.

When I try to view the XHTML source code from the browser, all it shows is my empty body element without any of the innerHTML stuff my script created within it.

Is this normal?  I thought that whatever was placed in innerHTML would be visible in the XHTML source if I looked at the source after the page was rendered.
Link to comment
Share on other sites

I don't think that I have ever seen the replaced html inside of the source code.. Take a look at a chat script that I am working on for a tutorial. http://www.thomashostings.net/chatTutorial.html . It is a bit buggy as of yet but you will see that I replace the message textarea with a login text input and button if you are not logged in. However, it never shows in the source. So I do not think that it is a rather serious issue. I have the xhtml doc type declared and I have no problem with the css or anything...

Good Luck,
Tom
Link to comment
Share on other sites

Well, this is all in relation to the calendar/appointment script I'm trying to make.

Because I've been relying on an external script to print everything (tables and the data inside) using innerHTML, they're not 'seeing' my external CSS file.  I figure that I can code the nested tables (one for the overall structure (3 months across by 4 months high), one for each calendar month) directly into the markup in order to ensure the CSS formatting works as a yearly calendar's overall structure will always remain the same (12 months to a year, at most 5 weeks/rows, depending on how late a month starts, a month).  All that will change are the dates, which are derived by the script.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.