Solved

Background colour of SPAN tags.

Posted on 2001-07-05
3
206 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
Comment Utility
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
Comment Utility
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
Comment Utility

 Perfect answer.
 
 Thanks.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
This article discusses how to create an extensible mechanism for linked drop downs.
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…

763 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now