Jump to content

Archived

This topic is now archived and is closed to further replies.

KevinM1

innerHTML + XHTML = bug

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?

Share this post


Link to post
Share on other sites
I've never heard of this issue... and if you don't use an XHTML doctype, you're fine?

Share this post


Link to post
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

Share this post


Link to post
Share on other sites
What do you mean by "source code"? Where isn't it appearing?

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites
Hmm....

Well, that stinks.  Looks like I'll have to code the tables directly into my markup.

Share this post


Link to post
Share on other sites
Why do you want the tables to be viewed in the source? I don't think that will really have any baring on what you are doing..

Tom

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites
That is strange... I've never really tested what happens to CSS attributes written out dynamically...

Share this post


Link to post
Share on other sites

×

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.