Solved

change color of div

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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

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 …
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…
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…

772 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