Document.write Formatted By Css

free web hosting
Open Discussion > CONTRIBUTE > Computers > Programming Languages > Java, Java Servlets, Java Script, & JSP

Document.write Formatted By Css

gaea
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

CODE
<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:
CODE
<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.

 

 

 


Reply

Tyssen
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:

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

Reply

gaea
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.
CODE
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.

Reply

Tyssen
QUOTE(gaea @ Apr 4 2006, 05:29 AM) *

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.

Reply

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

CODE

<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.

Reply

jlhaslip
Or use classes?

HTML
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.

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.

Similar Topics

Keywords : document formatted css

  1. Document.write & Noscript Questions (javascript) - (1)



Looking for document, write, formatted, css

*RANDOM STUFF*





*SIMILAR VIDEOS*
Searching Video's for document, write, formatted, css

*MORE FROM TRAP17.COM*
advertisement



Document.write Formatted By Css



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute your information that might help someone here.
Ask your Doubts & Queries to get answers.. "Together, We enlight each other!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE