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
Solved

change color of div

Posted on 2006-11-20
3
1,520 Views
Last Modified: 2010-05-18
Dear experts

I have a image and a text next to the image .. like this
“ IMAGE “   click on the image

Now when user clicks on the image, i am passing an id and  I am calling a function expandcontent. i.e
onClick="expandcontent(id)">
 and expandcontent function is this
function expandcontent(id){
 
       if (ccollect.length>0){
       document.getElementById(id).style.display=(document.getElementById('sc'+id).style.display!="none")? "none" : ""
            document.getElementById(id).src=(document.getElementById('sc'+id).style.display=="none")? expandsymbol : contractsymbol
            
      
      
}
}
In my jsp the div is placed right under the image.
The above function hides and unhides the div when user clicks on the image. Now my requirement is first time when user clicks on the image the div is unhidden  and the background color of the first row in that
div should change from white to blue. I am able to unhide the div but any idea how i can change the color.


Thanks
J
0
Comment
Question by:jaggernat
3 Comments
 
LVL 7

Accepted Solution

by:
gam3r_3xtr3m3 earned 400 total points
ID: 17984057
the code for changing the background color would be:

document.getElementById(id).style.backgroundColor = "#00f"; // #0000FF BLUE ; #FFFFFF WHITE

im not quite sure where you intend to change the background color though.
but whether div nor td the code would change the background color of the element.

hope that helps,
gam3r_3xtr3m3
0
 
LVL 10

Author Comment

by:jaggernat
ID: 17987384
thanks

can i write something like this
document.getElementById(id).style.backgroundColor =  (document.getElementById('color'+id).style.backgroundColor !="#0000FF")?"#0000FF":"#FFFFFF"

if background color is white change to blue, if blue change to white (my requirment)
possible?
thanks
J
0
 
LVL 28

Assisted Solution

by:Pravin Asar
Pravin Asar earned 100 total points
ID: 17988340
Since you want to show and changes color, it can be efficiently handled by css className

e.g.


<style type="text/css">
div.show { display: block; background-color: blue;  }
div.hide { display: none;  background-color: white; }
</style>
<script language="javascript">
function ShowHide (id, className) {
document.getElementById (id).className = className;
return false;
}
</script>
<a href="#" onclick="return ShowHide ('div1', 'show');">Show</a>
<a href="#" onclick="return ShowHide ('div1', 'hide');">Hide</a>
<div id="div1" >&nbsp;</div>
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Jqeury/JS: Mutiplying the difference in 2 dates and comparing to another number 2 29
Html Newline 7 21
JQuery Syntax... 4 37
Search Item in Table 2 22
In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
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…

828 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