Webforumz's RSS FeedRSS Webforumz RegistrationRegister Contact Webforumz StaffContact

Attaching styles/classes to Javascript. Help!

This is a discussion on "Attaching styles/classes to Javascript. Help!" within the Web Page Design section. This forum, and the thread "Attaching styles/classes to Javascript. Help! are both part of the Design Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Design Your Website > Web Page Design

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Sep 14th, 2006, 14:40
New Member
Join Date: Sep 2006
Location: UK
Age: 21
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Attaching styles/classes to Javascript. Help!

Hey everyone!

My first post on this forum - here goes! I have used CSS and Javascript seperatly with great effect before, but ive come up to a roadblock on the new site im working on. Either im just being dum or there really is something specific im supposed to be doing here.

In this case there is a live clock on my site. Part of the Javascript code is as follows:
var time=new Date();
var date=time.getDate();
var lmonth=months[time.getMonth() + 1];
var year=time.getYear();
if (year < 2000)
year = year + 1900;
document.write("<center><font size='1' face='Arial' font color='#006699'><b>" + date + " ");
document.write(lmonth + " " + year + "</b></center>");


So you get the picture, quite simple. Problem is i want to change the font to 12pt which must be done with stylesheets. I made a seperate file with all my CSS in, and linked to it in the header of my page. I then tried various ways of putting the class to change the size of the font into this javascript, but it would always make the whole thing just stop working! where am I going wrong?

Thanks for any advice!

Steven.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #2  
Old Sep 14th, 2006, 15:53
Most Reputable Member
Join Date: Apr 2006
Location: Cornwall, UK
Posts: 1,310
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Attaching styles/classes to Javascript. Help!

Just wrap your clock in a <div id='clock'> and style in your css file in the normal way should do the job.

Also don't not use proprietary attributes as you have in your code.

To change the text within the div, use - document.getElementById('clock') - to get the parent node within the DOM and change this parents child node.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
attaching, stylesclasses, javascript, help

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
attaching files aashishahuja PHP Forum 2 Jun 1st, 2008 03:42
Problem attaching PHP to webpages thumbliner PHP Forum 6 Apr 20th, 2008 16:23
CSS conflicting styles ttaxi Web Page Design 2 Mar 28th, 2008 18:01
Uploading a Cv and attaching to an email Gurpreet82 Classic ASP 4 Mar 3rd, 2006 22:34
Styles in classes? timmytots Web Page Design 4 Dec 2nd, 2005 02:20


All times are GMT. The time now is 19:43.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8