Change font color of javascript text message

  • wpas
  • Proficient
  • Proficient
  • User avatar
  • Posts: 378
  • Loc: Canada

Post 22 days ago

In a javascript program I am using the following message array:

var mesge=new Array();
mesge[0] = "Hello and Welcome to Telscripts, All In One Website!"
mesge[1] = "Available here are useful scripts to make your web pages Dynamic!"
mesge[2] = "Have a look around and see if you find any script you like."

Is there a way to set the font color of each message.

For example I would like:

mesge[0] = Green
mesge[1] = Blue
mesge[2] = Green

I would like to be able to change the font color within each mesge[] above similar to what is done with HTML or even PHP

I do not want to add any other executable or print type statements.

Would appreciate some help

Thanks
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9193
  • Loc: Seattle, WA & Phoenix, AZ

Post 20 days ago

Where are these being shown? Via an alert message? If it is via an alert message you cannot style the content. If you are using some sort of modal then you could probably style using HTML/CSS.

Really depends on where the content is being shown.
  • wpas
  • Proficient
  • Proficient
  • User avatar
  • Posts: 378
  • Loc: Canada

Post 20 days ago

They are used as scrolling messages on a web page
  • PolishHurricane
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1587

Post 17 days ago

With the code you gave, you could possibly go into each line and do something like this:

Code: [ Select ]
var mesge=new Array();
mesge[0] = '<span style="color: #00ff00; ">Hello and Welcome to Telscripts, All In One Website!</span>';
mesge[1] = '<span style="color: #0000ff; ">Available here are useful scripts to make your web pages Dynamic!</span>';
mesge[2] = '<span style="color: #00ff00; ">Have a look around and see if you find any script you like.</span>';
  1. var mesge=new Array();
  2. mesge[0] = '<span style="color: #00ff00; ">Hello and Welcome to Telscripts, All In One Website!</span>';
  3. mesge[1] = '<span style="color: #0000ff; ">Available here are useful scripts to make your web pages Dynamic!</span>';
  4. mesge[2] = '<span style="color: #00ff00; ">Have a look around and see if you find any script you like.</span>';


However, the proper way to do it, to reduce redundancy, would be, wherever your "mesge" array is written to the page, you would possibly just wrap your output in tags or something with a CSS style, or you could make another array for the colors in the same order and do something like: document.write('<span style="color: '+mesge_colors[i]+'; ">'+mesge[i]+'</span>');

Sky is the limit, depends on the code, you didn't provide enough! :P
  • wpas
  • Proficient
  • Proficient
  • User avatar
  • Posts: 378
  • Loc: Canada

Post 17 days ago

I tried that but the color does not change.
It actually just prints out the <span style......along with the message

Post Information

  • Total Posts in this topic: 5 posts
  • Users browsing this forum: No registered users and 47 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2017. Ozzu® is a registered trademark of Unmelted, LLC.