Need help....Changing text color in every refresh

HTML, CSS and anything else that deals with client side capabilities.

Moderator: General Moderators

Post Reply
joinnavdev
Forum Newbie
Posts: 21
Joined: Thu Feb 05, 2015 2:34 pm

Need help....Changing text color in every refresh

Post by joinnavdev »

Hi All,

Appreciate help in resolving the below issues.....

With every refresh I wanted to change the text color in marquee tag by calling javascript function......
I am getting color code like #18EEC5 ......but when calling script function from marquee tag nothing is happening......

Code: Select all

<html>
    <head>
		<script type="text/javascript">
				function getRandomColor() {
				var letters = '0123456789ABCDEF';
				var color = '#';
				for (i = 0; i < 6; i++ ) {
					color += letters[Math.floor(Math.random() * 16)];
				}
				return color;
				}				
		</script>
	</head>
    <body>	
			<script> 
				$col=getRandomColor();
				document.write(getRandomColor()); 						
			</script>
			<marquee style="color: 'document.write(getRandomColor())'; font-size: 20pt; font-weight: bold">
				Text Color Changes
			</marquee>
	</body>
</html>
Thanks,
Nick
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Need help....Changing text color in every refresh

Post by requinix »

Javascript and CSS don't work that way.

If you want to change the color then you have to write some Javascript that uses the DOM to locate the <marquee> and change its text color. With that page you can do it by

Code: Select all

document.getElementsByTagName("marquee")[0].style.color = getRandomColor();
joinnavdev
Forum Newbie
Posts: 21
Joined: Thu Feb 05, 2015 2:34 pm

Re: Need help....Changing text color in every refresh

Post by joinnavdev »

Hi,

Thx.....you are right......

Your help is highly appreciated.

Thanks,
Nick
Post Reply