?
Solved

javascript change span color

Posted on 2007-11-24
3
Medium Priority
?
5,824 Views
Last Modified: 2010-08-05
I only know a span can be given an id. How can  its color be changed in javascript?
Thanks.
0
Comment
Question by:ksfok
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 54

Accepted Solution

by:
b0lsc0tt earned 1000 total points
ID: 20344209
ksfok,

The background color can be changed with ...

document.getElemementById('theSpan').style.backgroundColor = 'red';

Let me know if you have any questions or need more information.

b0lsc0tt
0
 
LVL 17

Assisted Solution

by:gops1
gops1 earned 1000 total points
ID: 20344621
Some different ways to change span color:
<html>
	<head>
		<title>Script Demo Gops&reg;</title>
		<style>
			body, input, div, a, span{font-family:verdana;font-size:11px;}
			span{cursor:hand;cursor:pointer;}
			#coCSS{background-color:#7CA6A6;}
		</style>
		<script language="javascript">
			function changeColor() {
				var o = document.getElementById('btnClick');
				o.style.backgroundColor='#9166E6';
			}
		</script>
	</head>
	<body>
		<span id="coCSS">I am a Span I am colored with CSS</span>
		<br><br><br>
		<span id="coClick" onclick="this.style.backgroundColor='#D5FF00'">I am a Span Click me to change color</span>
		<br><br><br>
		<span id="btnClick">I am a Span, change my color by clicking on [CHANGE COLOR] button</span>
		<input type="button" onclick="changeColor()" value="CHANGE COLOR">
	</body>
</html>

Open in new window

0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 20417367
I'm glad I could help.  Thanks for the grade, the points and the fun question.

bol
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question