Solved

Background colour of SPAN tags.

Posted on 2001-07-05
3
210 Views
Last Modified: 2010-05-18
I give up on this...
None of these javascript lines will set the background colour.
Any ideas ?

This needs to work in both IE and Netscape, including NS6 if possible.

------------------------

<span name="testt" > This should have a nasty red background </span>
<br>

<script>


//function to set span background color
function setcol() {
     //document.testt.style.background='#ff0033';     //NO
     //testt.style.background='#ff0033';          //NO          
     //testt.background='#ff0033';               //NO
     //document.testt.style.backgroundcolor='#ff0033';     //NO
     //testt.style.backgroundcolor='#ff0033';          //NO
     testt.backgroundcolor='#ff0033';               //NO
}

setcol();
</script>


<br>
<span name="testt2" style="background:#ff0033" > Like this </span>

----------------------

Thanks, quick, clear response will earn an A grade.
0
Comment
Question by:coopa
[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 9

Accepted Solution

by:
nimaig earned 100 total points
ID: 6256034
Try this

<html>
<HEAD>

<SCRIPT LANGUAGE="JavaScript">
<!--
     function setcol(myColor) {
          if(document.all){
              window.spanTest.style.backgroundColor=myColor;              
         }else if(document.layers){
              document.spanTest.bgColor=myColor;
         }
     }
//End-->
</script>
</HEAD>
<body>
<span id="spanTest" name="spanTest" style="position:relative" > Like this </span>
<form>
     <input type="button" value="change color" onClick="setcol('#00FFFF')">
</form>
</body>
</html>
0
 
LVL 9

Expert Comment

by:nimaig
ID: 6256055
The above works with IE and netscape 4.7. I don't have any idea of Netscape 6.0
0
 
LVL 2

Author Comment

by:coopa
ID: 6256070

 Perfect answer.
 
 Thanks.
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Why is my $_POST not going to results page 10 69
Put javascript to get dropdown value 3 34
Check input text, Number 7 55
Why does my submit button remain disabled 3 36
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…

752 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