Solved

Background colour of SPAN tags.

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

Independent Software Vendors: 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

Suggested Solutions

Title # Comments Views Activity
Validating Date Part2 2 27
How can I use Javascript to insure proper entry of URL? 6 26
DataTable column sorting incorrectly 2 19
Calculating percentage 2 29
In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
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-…
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…

749 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