Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Background colour of SPAN tags.

Posted on 2001-07-05
3
Medium Priority
?
215 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 400 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

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

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

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
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…

721 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