Jump to content
xisto Community
Sign in to follow this  
gaea

Document.write Formatted By Css

Recommended Posts

There is probably a mind numbingly easy way to do this...but it's driving me nuts. Basicly I use javascript to write out a varaible

<script src="http://antiwar.com/ewens/counter/casualties.js"></script><script>document.write(casualties.total_value);</script>

So good so far. But then I want to formatt in in a specific way using css. But I can't get it to actually change the formatting.

I tried:
<script src="http://antiwar.com/ewens/counter/casualties.js"></script><script>document.write(<font STYLE=font-family: Arial; font-size:12pt> +casualties.total_value+</font>);</script>
as well as using the <div> tag, and even setting the <td STYLE=> (forgot to mention that it's in a table).

All of that doesn't make any change. This is starting to get really obnoxious. Any help would be appreciated.

Share this post


Link to post
Share on other sites

You can't use JS to document.write styles to the head of the document but rather you use it to change pre-existing styles on your page. For instance, if you have a div called #content on your page, you can do something like:

var myDiv = getElementByID('content');myDiv.style.background-color = '#FFF';

Share this post


Link to post
Share on other sites

Thanks for the tip...but that's not exactly what i meant. I wasn't trying to write new styles to the header, only trying to get the text created by document.write to follow the formatting rules of my stylesheet.

 

Anyways, I resolved that issue by creating the table cell in the document.write call.

document.write('<td class="counters" width=45 height=3 border=3 bordercolor=#000000>'+casualties.total_value+'</td>');

Only problem now is that it is completely ignoring the hight, width, and border values. Quite strange.

 

Maybe it's just me, but javascript seems a great deal more fickle than something like php. I always run into the weirdest of problems.

Edited by gaea (see edit history)

Share this post


Link to post
Share on other sites

Maybe it's just me, but javascript seems a great deal more fickle than something like php. I always run into the weirdest of problems.

Yeah, JS isn't my strong suit either.

Share this post


Link to post
Share on other sites

If you are unable to write the text that is styled as what it's been configured to, you can try the following.

<span style=”font-family: Arial; font-size:12pt”> <script src="http://antiwar.com/ewens/counter/casualties.js"></script> <script>document.write(casualties.total_value);</script></span>

This code make sures that whatever text that is inside the span division will be styled as configured.

Share this post


Link to post
Share on other sites

Or use classes?

In the html:<span class=?special?><script src="http://antiwar.com/ewens/counter/casualties.js"></script><script>document.write(casualties.total_value);</script></span>In the Css:.special { font-family: Arial; font-size:12pt; }

That takes the formatting out of the document and places it into the css file. Makes it more readily changed for the skin or template.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.