Solved

Background colour of SPAN tags.

Posted on 2001-07-05
3
208 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
  • 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

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
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…

778 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