Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

change color of div

Posted on 2006-11-20
3
Medium Priority
?
1,541 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 1600 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 400 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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'…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

876 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