Solved

change color of div

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
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 …
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…

758 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

21 Experts available now in Live!

Get 1:1 Help Now