Solved

change color of div

Posted on 2006-11-20
3
1,524 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
[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
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 29

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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…
Suggested Courses

751 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