|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today! |
|
#1
|
|||
|
|||
|
Trouble changing the text style of an element
Hello! I am attempting to write a script that will allow a user to change certain things about how a page is displayed. The PHP part has been completed, but I am having trouble with the JavaScript that does the changing. I have included it below:
Code:
<script language="JavaScript" type="text/javascript">
<!--
function changetext() {
/* preferably, I would like to apply this
to the whole document instead of just
one part */
var what = document.getElementByID("content");
what.style.textSize = "4";
what.style.color = "green";
/* normally those values above would
come from PHP variables */
}
document.onLoad = changetext;
//-->
</script>
<div id="content">Some text to style</div>
Can anyone see anything wrong with this code? Please be gentle and patient with me as I am no JS expert. In fact, I try to avoid it when possible. Thank you very much for your help in advance! Joe of Christ For Life
__________________
Check out 4Life today! Last edited by Joe4JC : October 9th, 2003 at 08:30 PM. |
|
#2
|
||||
|
||||
|
Since JS is case sensitive, your calling of the getElementById will not work... simply change the last letter to lower-case, and you're rocking.
Also, I've not seen the "textSize" property before - try "fontSize" instead, and don't forget to specify your unit of measurement (px, pt, mm, etc) |
|
#3
|
||||
|
||||
|
Failing that, try creating classes with the different font sizes/colors and change the class instead of the style. I know I've made that work before. I can't help thinking that using what.style may not be cross-platform, but what.class seems to work across the board.
|
|
#4
|
||||
|
||||
|
Yeah - you're on the right track dhouston - using classes in a seperate CSS file means that you can better seperate your presentation from your business logic (if you are a CSS purist...*coughFrankieShakescough*
)Bottom-line is, setting special case styles individually isn't usually a good idea as it makes updating a hassle. |
|
#5
|
|||
|
|||
|
Thank you guys for your ideas; the suggestions stumpy first made are probably what I am looking for. Yes, I do use separate style sheets, but the reason I can not use classes for the text style is because the font size and colour values are coming from user input. I will let you guys know how well the changes work.
Joe |
|
#6
|
|||
|
|||
|
Allright guys, I made the changes and no dice. It took me several days to figure out that "document.onload" should have been "window.onload"!
Oddly enough, I couldn't find any tutorials that mentioned that! Instead, I had to take it from another script. ![]() |
![]() |
| Viewing: Dev Articles Community Forums > Programming > JavaScript Development > Trouble changing the text style of an element |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|