JavaScript - Collapsing/expanding
Hi,
I am trying to do a FAQ section on a site. New to this stuff. What I would like to do is: 1.Question 2.Answer (Question and part of an answer are visible) 3. A button for expanding/collapsing. I am trying to do a button that changes on hover,and when text is expanded image changes, then on hover it changes again and if I press I collapse it to the original image). What I got so far is this: Code: <head> <style type="text/css"> .divVisible {display:block;} .divHidden {display:none;} #test {background-color: red;} </style> <script language="javascript" type="text/javascript"> var divID = "MyDiv"; function CollapseExpand() { var divObject = document.getElementById(divID); var currentCssClass = divObject.className; if (divObject.className == "divVisible") divObject.className = "divHidden"; else divObject.className = "divVisible"; } function changeImage() { document.images["Button1"].src= "less.png"; return true; } function changeImageBack() { document.images["Button1"].src = "more.png"; return true; } </script> </head> <body> <div id="test"> <div> TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST </div> <div id="MyDiv" class="divHidden"> - TEST TEST TEST TEST - TEST TEST TEST TEST - TEST TEST TEST TEST - TEST TEST TEST TEST - TEST TEST TEST TEST </div> </div> <A href="#" onMouseOver="return changeImage()" onMouseOut= "return changeImageBack()" input id="Button1" type="button" onClick="return CollapseExpand()" ><img name="Button1" src="less.png" width="81" height="42" border="0" alt="javascript button"></A> </body> </html> I tried different stuff but couldn't connect 4 images. (more.png, morehover.png, less.png, lesshover.png). Thnx in advance G. Similar TutorialsHi all, I'm using the scripts from Dynamic Drive http://www.dynamicdrive.com/dynamici...edcollapse.htm to create a sliding collapsing/expanding div. I need to modify it slightly so instead of an image for the toggle, it has text hyperlink - changing from "Show More" to "Show Fewer". Can anyone help? Thanks http://www.mainstudio.com/ Can anyone recommend a code to create an expandable panel similar the one in this link, but one which expands and collapses horizontally as opposed to vertically? Also, to include the functionality of having content inside each panel load only after its clicked. Hey, I'm having trouble with this site http://bit.ly/hL0u0w... If you go to the services section you will see a sub navigation on the left of the box. The idea of this is to have sub sections within the main headings that expand/collapse when selected. Insted when any one link is clicked the whole menu expands and not just the related sub sections. This is the javascript Quote: <script type="text/javascript"> $(document).ready (function() { $('#link1').click(function() { $('.slide').slideToggle('fast'); }); $('.close').click(function() { $('.slide').slideUp('fast'); }); $(document).ready (function() { $('#link2').click(function() { $('.slide').slideToggle('fast'); }); $('.close').click(function() { $('.slide').slideUp('fast'); }); }); $(document).ready (function() { $('#link3').click(function() { $('.slide').slideToggle('fast'); }); $('.close').click(function() { $('.slide').slideUp('fast'); }); }); }); </script> and here is the html Quote: <div id="subnav4"> <ul class="navigation4 pagination"> <li class="tab4"><a rel="1" id="link1" href="#">heading 1</a></li> <li style="display: none;" class="dome slide"><a href="#">corporate id</a></li> <li style="display: none;" class="dome slide"><a href="#">branding</a></li> <li style="display: none;" class="dome slide"><a href="#">brochures</a></li> <li style="display: none;" class="dome slide"><a href="#">direct mail</a></li> <li class="tab4"><a id="link2" href="#">heading 2</a></li> <li style="display: none;" class="dome slide"><a href="#">email marketing</a></li> <li style="display: none;" class="dome slide"><a href="#">websites</a></li> <li class="tab4"><a id="link3" href="#">heading 3</a></li> <li style="display: none;" class="dome slide"><a href="#">advertising</a></li> <li style="display: none;" class="dome slide"><a href="#">audiovisual</a></li> <li class="tab4"><a id="heading 3" href="#">exhibitions</a></li> </ul> </div> Hope someone can help with this! Many thanks! http://www.codingforums.com/showthread.php?t=87742 I've been using the advice and code here to start incorporating expanding/collapsing tables into my work, but I'm hitting a little problem. I want to have multiple such tables side-by-side (each headed by a picture and populated by a lightbox, which isn't the issue), but Dreamweaver wants nothing to do with the idea. I don't really even know if it's possible, but if it is I'd like to know what sort of changes I might need to make to achieve it.
Hello everyone! I'm newly managing a small college website with next to no experience. There is a file called "bios.js" which creates expanding/collapsing li's. The problem is that I've put some hyperlinks into the expanded content, and it seems that "bios.js" is in front of, so clicking the hyperlink simply collapses the list item instead of opening the link. Is there any way to: a) have the hyperlinks trump the javascript? b) Make "bios.js" apply to the title class of the list item rather than the list item itself? I'm new to this, so I'm not going to post 100 lines of code before I know if it's doable. And if you reply to this, perhaps you could give me a hint as to what part of the code I should post (the open-hover portion?). Thanks all! I would like to create collapsing boxes. I would like for them to have different colors. Box1 Box 3 Link 1 Link 1 Link 2 link 2 Link 3 Link 3 Box2 Box 4 Link 1 Link 1 Link 2 link 2 Link 3 Link 3 I got the code to do the first column (box 1 and 2). But I don't know how to add a second column (box 3 and 4). Any help would be appreciated. Thanks how do i make this table's initial state to be collapsed rather than expanded Code: <html xmlns="http://www.w3.org/1999/xhtml" > <head><title> Untitled Page </title> <script type="text/javascript"> function poorman_toggle(id) { var tr = document.getElementById(id); if (tr==null) { return; } var bExpand = tr.style.display == ''; tr.style.display = (bExpand ? 'none' : ''); } function poorman_changeimage(id, sMinus, sPlus) { var img = document.getElementById(id); if (img!=null) { var bExpand = img.src.indexOf(sPlus) >= 0; if (!bExpand) img.src = sPlus; else img.src = sMinus; } } function Toggle_trGrpHeader2() { poorman_changeimage('trGrpHeader2_Img', 'http://www.saintjoe.edu/info_systems/help/email/minus_sign.gif', 'http://www.mumstudents.org/~gwang/Safari_Books/PHP%20Advanced%20for%20the%20World%20Wide%20Web/1.3_files/sign_plus.gif'); poorman_toggle('row1'); poorman_toggle('row2'); poorman_toggle('row3'); } function Toggle_trGrpHeader1() { poorman_changeimage('trGrpHeader1_Img', 'http://www.saintjoe.edu/info_systems/help/email/minus_sign.gif', 'http://www.mumstudents.org/~gwang/Safari_Books/PHP%20Advanced%20for%20the%20World%20Wide%20Web/1.3_files/sign_plus.gif'); poorman_toggle('trRow1'); } function IMG1_onclick() { } function IMG2_onclick() { } function IMG8_onclick() { } function IMG10_onclick() { } function IMG12_onclick() { } function IMG13_onclick() { } </script> </head> <body style="font-size: 12pt"> <div> <table border="0" style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; cursor: crosshair; padding-top: 0px; background-color: transparent; border-right: gray thin solid; border-top: gray thin solid; border-left: gray thin solid; border-bottom: gray thin solid;" cellpadding="1" cellspacing="0" align="center"> <tr> <td colspan="12" style="border-bottom: gray thin solid; text-align: center; height: 25px;" class="titlebg"> <span class="titlebg" style="color: gray">Our Affiliates</span></td> </tr> <tr id="trGrpHeader2"> <td class="number" colspan="4" rowspan="4" style="border-right: gray thin dashed;"> <span onclick="javascript:Toggle_trGrpHeader2();"> <img id="IMG12" src="http://img48.imageshack.us/img48/3168/viewallcopyjo5.png" language="javascript" onclick="return IMG12_onclick()" /></span></td> <td colspan="1" style="width: 71px; height: 11px;"><img id="Img5" src="http://sz-ex.com/affiliates/socal1.gif" language="javascript" onclick="return IMG2_onclick()" /></td> <td colspan="1" style="width: 63px; height: 11px;"><img src="http://sz-ex.com/affiliates/ff1.gif" /></td> <td colspan="1" style="width: 76px; height: 11px;"><img id="Img6" src="http://zcoarea.ckc.com.ru/image3.gif" language="javascript" onclick="return IMG1_onclick()" /></td> <td colspan="1" style="width: 51px; height: 11px;"><img id="Img7" src="http://sz-ex.com/affiliates/ssd1.gif" language="javascript" onclick="return IMG2_onclick()" /></td> <td colspan="1" style="width: 40px; height: 11px"> <img id="IMG8" src="http://sz-ex.com/mini_v2-1.gif" language="javascript" onclick="return IMG8_onclick()" /></td> <td colspan="1" style="width: 55px; height: 11px"> <img id="IMG10" src="http://i114.photobucket.com/albums/n267/f2a/FTAV1.jpg" language="javascript" onclick="return IMG10_onclick()" /></td> <td class="number" rowspan="4"> </td> <td class="number" rowspan="4" style="width: 80px; text-align: center; border-left: gray thin dashed;"> <img id="IMG13" src="http://img61.imageshack.us/img61/613/minibanneruf1.gif" language="javascript" onclick="return IMG13_onclick()" start="" /><br /> <span style="font-size: 8pt; color: dimgray"></span></td> </tr> <tr id="row1"> <td class="number" rowspan="3" style="width: 71px; height: 22px"> <img src="http://sz-ex.com/affiliates/ff1.gif" /></td> <td class="number" rowspan="3" style="width: 63px; height: 22px"> <img id="IMG2" src="http://sz-ex.com/affiliates/socal1.gif" language="javascript" onclick="return IMG2_onclick()" /></td> <td class="number" rowspan="3" style="width: 76px; height: 22px"> <img id="Img11" src="http://i114.photobucket.com/albums/n267/f2a/FTAV1.jpg" language="javascript" onclick="return IMG10_onclick()" /></td> <td class="number" rowspan="3" style="width: 51px; height: 22px"> <img id="Img9" src="http://sz-ex.com/mini_v2-1.gif" language="javascript" onclick="return IMG8_onclick()" /></td> <td class="number" rowspan="3" style="width: 40px; height: 22px"> <img id="Img4" src="http://zcoarea.ckc.com.ru/image3.gif" language="javascript" onclick="return IMG1_onclick()" /></td> <td class="number" rowspan="3" style="width: 55px; height: 22px"> <img id="Img3" src="http://sz-ex.com/affiliates/ssd1.gif" language="javascript" onclick="return IMG2_onclick()" /></td> </tr> <tr id="row2"> </tr> <tr id="row3"> </tr> </table> </div> </body> </html> Hello! I am trying to collapse a table via JS, and the following code works in IE, yet not in Mozilla. I have read lots of other posts (on the world wide web) in regards to possibly tackling this with div, or span: however, in my case, I cannot modify the already existing HTML of the code. Could you please assist me - why is it that the following code works in IE, yet not in Mozilla? More INFO: Please note that although I am using the variable id below, I have also tried this via the defined element el. However -- using el doesn't work in either browsers. Please also note that the function is being called like so: HTP.p( '<table BORDER=0 BORDERCOLOR="#d1dce9" CELLPADDING="0" WIDTH=100% style="border-collapse:collapse;"> <tr> <td onClick="ftoggle(this);" width="100%" style="cursorointer;"><font face="Calibri" color ="#3A5894" size=2><B>[+] Click here to Show/Hide the Table</B></font></td> </tr><tr> <td colspan="1" style="display:none;color:#ff0000;">'); <head> <script language="JavaScript"> function ftoggle(id){ var el = document.getElementById(id); if(id.parentNode.nextSibling.childNodes.item(0).style.display=="") { id.parentNode.nextSibling.childNodes.item(0).style.display="none"; } else { id.parentNode.nextSibling.childNodes.item(0).style.display=""; } } </script> </head>'); Ahoy, Lemme try to explain this as best as I can. Bullet points might help: When someone clicks on an image here (http://gta.kwivia.co.uk/gta-iv/), the rest of the images collapse and become invisible Below the image, some links appear Also, there will be a "show other images" button which will then show the rest of the images http://gta.kwivia.co.uk/gta-iv/ I will appreciate all solutions to this problem. If you need to know anything, simply ask me. If this is in the wrong forum please move it. I'm new to Javascript so I'm not so much aware of the types as of yet. I'm using Javascript for the first time, and I've used it on my blog to create a blog archive. However, I want it to be set out like this: Menu Item 1 [Click to expand] -Sub Item 1.1 [Click to expand] -Sub Item 2.1 [Click to get to page] Menu Item 1 is expanding fine, and I know how to get Sub Item 2.1 to link to the page, however I can't seem to link Sub Item 1.1 to expand. Can someone help please? URL: http://dinotamermeep.blogspot.com/p/blog-archive.html Thank you, -Meepski Hello, I created a page which has 12 collapsible panels, each can be opened and closed independently but i would like to have one button on the page that expands all the content, for printability. Below is the section of javascript that relates to the original state of the collapsible panel. When I change the this.contentIsOpen to be true all the panels expand. I would like a way of linking this function to a button. Code: Spry.Widget.CollapsiblePanel.prototype.init = function(element) { this.element = this.getElement(element); this.focusElement = null; this.hoverClass = "CollapsiblePanelTabHover"; this.openClass = "CollapsiblePanelOpen"; this.closedClass = "CollapsiblePanelClosed"; this.focusedClass = "CollapsiblePanelFocused"; this.enableAnimation = true; this.enableKeyboardNavigation = true; this.animator = null; this.hasFocus = false; this.contentIsOpen = false; }; Many thanks Liam Code: function initMenu(){ var menus, menu, text, a, i, CurrentID; menus = getChildrenByElement(document.getElementById("menu")); CurrentID = document.getElementById("auto"); for(i = 0; i < menus.length; i++){ menu = menus[i]; text = getFirstChildByText(menu); a = document.createElement("a"); menu.replaceChild(a, text); a.appendChild(text); a.href = "#"; a.onclick = showMenu; a.onfocus = function(){this.blur()}; } //CurrentID.showMenu; thought this would work but it doesn.t } I am modifying a website for a company I am interning at. I have no javascript experience and was just thrown in. I need the menu to open when page is clicked so that it looks like the menu stayed open when you made a selection and the new page loads. I have a id in the html of the pages called "auto" to designate the menu item in the page to be opened. If anyone could help I would be very grateful. I will be keeping a lookout for posts Can anyone show me the code for a simple expanding navigation bar? I need to roll over the nav bar and for it to drop down with more options. I know the code will be straight forward, I can't work it out though. Thanks whoever can help = ) Hi All, My apologies if this is answered in a previous post but my searches didn't turn up a solution. I need an expanding, vertical menu, virtually identical to: http://www.dynamicdrive.com/dynamici...enu-glossy.htm but with one change. The menu subheaders, ie, "CSS Examples, CSS Drives" are currently just text and their background is defined in the CSS. I need to make these menu subheaders rollover graphics instead of text. It is easy to replace the submenu items themselves with rollover graphics instead of text, but the menu subheaders have defeated me. Is there a cunning solution to this? Regards Gary Hey everyone, I'm a little new to JS coding but I am trying to design a simple system that I hope you can help me with. Basically, I want to know which is the best approach to this problem, or a direction where I can find info about it. The web application I designed uses basic PHP with basic JS and very basic Ajax which populates some divs with MySQL data. I went with a more "Web 2.0" approach instead of having a page for everything; I wanted to create dynamic pages. That's the gist of how the site works... OK. The issue is I have a table that is populated via a PHP script pulling from a MySQL database. This works fine. What I need is a way (via some clickable region on each <tr> element maybe?) to expand each table "row" to show a form to do some database updates. I don't need the full CRUD, just Read/Update and I am trying to write it as simple as possible. I do not need help on the form, I just need a direction or suggestion on how to accomplish the act of displaying the form, or call it the "expanding rows which reveal a web form for database interaction". I have seen some nice Ajax ways, but I am only a beginner when it comes to those techniques and am not in the habit of taking work from other people and using it on something I am creating (and I learn more this way too; the whole "teach a man to fish vs. give a man a fish") Option#1: What I was thinking was a way to "hide" the form which could already exist on every row, but then "show" it via an expand function? Option#2: Or maybe a generic hidden div that has the form on it, placed on the next row down when clicked,.. but then how would the form know which row to edit via MySQL? I think option 1 sounds better..... Again, I need help on making this form pop up on each table row. Any help or direction would be greatly appreciated. Sample code follows: Code: <table> <thead> <tr> <th>ID</th> <th>Name</th> <th>Number</th> <th>Address</th> <th>Email</th> <th>Alt Number</th> </tr> </thead> <tbody> //<!--Some PHP code that populates all table rows, every row is a row in the database like below-->// <tr> <td onclick="javascriptfunction(this)">foo</td> <td>bar</td> <td>data</td> <td>from</td> <td>MySQL</td> <td>Database</td> </tr> <div id="PopUpForm"> <form id="form_id" name="form_name" action="foo.php" method="post"> <input type="hidden" name="id" value="//<!--Value of MySQL ID-->//"/> <table title="myTable" style="margin: auto; display:hidden"> <tr class ="theader2"><th colspan="2">TEST TABLE</th> </tr> <tr> <td class="header">Some Field: </td> <td class="selector"><select name="foo" style="width: 150px;" id="foo"> <option value="" selected="selected">-- Select Value --</option> <tr> <input type="submit" value="Submit" class="btn"/> </form> </div> //<!--Some PHP code ends here-->// </tbody> Any help would be greatly appreciated =) Hi all, I am looking to create this in JS/DHTML/CSS that I found in a flash script you can view he http://www.melodicmedia.com/dev/expa...ash_flash.html I want the red expanding and contracting circle to be on top of a image so it only shows the parts of the image that the circle is around. Any help you have would be much appreciated =) Thank you =) Light and Love and Healing to you, -Patrick Arden McNally Hi. I am trying to learn how to make a Javascript menu for my webpage. I have made the menu and it works. I can collapse a submenu when I click on the menu header. I wan't it to start collapsed and then open a menu item when you click on it. I have figured out that it have something to do with the function Closeall(). But can't figure out what. Perhaps someone in here can help me or perhaps help me make a better menu. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> <title>IT-Menu</title> <script type="text/javascript" language="javascript1.3"> function closeall() { var divs=document.getElementsByTagName('div') for(var i=0; i<divs.length; i++) divs.style.display='none'; } function clicked(element) { var div=document.getElementById(element) if(div.style.display=='none') div.style.display='block'; else div.style.display='none'; return; } </script> </head> <body> <a href="#" onclick="clicked('MENU1')">MENU1</a><div id="MENU1"> <a href="#">SUBMENU1</a> <br /> <a href="#">SUBMENU2</a> </div> <br /> <a href="#" onclick="clicked('MENU2')">MENU2</a><div id="MENU2"> <a href="#">SUBMENU1</a> <br /> <a href="#">SUBMENU2</a> </div> </body> Hello all, Firstly apologies for my javascript ignorance - I'm not a programmer, just someone thrust into programming since there's no-one else at my company who can do it. I found a nice js script online for a drop-down menu where the drop downs both expand to their full size and fade-in (very quickly) from transparent. The script in action can be seen on the script writer's site he http://sandbox.leigeber.com/dropdown-menu/index.html and the script is: Code: var menu=function(){ var t=15,z=50,s=6,a; function dd(n){this.n=n; this.h=[]; this.c=[]} dd.prototype.init=function(p,c){ a=c; var w=document.getElementById(p), s=w.getElementsByTagName('ul'), l=s.length, i=0; for(i;i<l;i++){ var h=s[i].parentNode; this.h[i]=h; this.c[i]=s[i]; h.onmouseover=new Function(this.n+'.st('+i+',true)'); h.onmouseout=new Function(this.n+'.st('+i+')'); } } dd.prototype.st=function(x,f){ var c=this.c[x], h=this.h[x], p=h.getElementsByTagName('a')[0]; clearInterval(c.t); c.style.overflow='hidden'; if(f){ p.className+=' '+a; if(!c.mh){c.style.display='block'; c.style.height=''; c.mh=c.offsetHeight; c.style.height=0} if(c.mh==c.offsetHeight){c.style.overflow='visible'} else{c.style.zIndex=z; z++; c.t=setInterval(function(){sl(c,1)},t)} }else{p.className=p.className.replace(a,''); c.t=setInterval(function(){sl(c,-1)},t)} } function sl(c,f){ var h=c.offsetHeight; if((h<=0&&f!=1)||(h>=c.mh&&f==1)){ if(f==1){c.style.filter=''; c.style.opacity=1; c.style.overflow='visible'} clearInterval(c.t); return } var d=(f==1)?Math.ceil((c.mh-h)/s):Math.ceil(h/s), o=h/c.mh; c.style.opacity=o; c.style.filter='alpha(opacity='+(o*100)+')'; c.style.height=h+(d*f)+'px' } return{dd:dd} }(); with Code: var menu=new menu.dd("menu"); menu.init("menu","menuhover"); used on my html page to call the script. I'm using the script exactly as written and exactly as it is on the dude's demo page for it. However, some of my sub-menu items are wider than their parent items and in IE7 this means they are bound to the width of the parent until the animations have finished, and then pop-out to their full width (NB not an issue in FF3). I'm actually not too fussed about either the fade in or expand out effects (they'd be nice, but not at the expense of the IE7 bug) so I simply wanted to know what I should do to the script to turn off the effects, or make them instant - ie reduce the length of the effect to as short as possible. I understand I can get rid of the bug by specifying a width for the ul element in my css, but I'd rather not do that if I can help it. I'd appreciate anyone's insight on this. Thanks Tom Hi, I'm having trouble figuring out why my image is disappearing when the user clicks on the arrow image to expand text for viewing. The arrow image only disappears if the link text is is more than one line. It remains if the link is only one line of text. Here is the code: HTML code: Code: <div class="ws-webpart> <div class="hidecat1"></div> <div class="hidecat1"> <!--This comment line added please dont remove this comment line --> <a class="hidecat2" id="za0.91" onclick="showHide('a0.91')" href="javascript:void(0)">Lorem ipsum dolor sit amet</a> </div> <div style="display:none;" id="a0.91"> <!--This comment line added please dont remove this comment line --> <div class="hideqst1"> <a id="sb0.913.92" class="hideqst2" onclick="showHide('b0.913.92')" href="javascript:void(0)"> Sed lectus lectus, varius quis vestibulum non, molestie vel est. Integer enim quam, elementum vel ornare non, egestas non augue. Ut varius vulputate mi, </a> </div> <div style="display:none;" id="b0.913.92"> <!--This comment line added please dont remove this comment line --> <div class="hideAns"> <p>Fusce suscipit tempus magna eget eleifend. Ut lacinia, turpis ac tempus euismod, nulla ipsum vehicula sem, et laoreet augue nunc in neque. Maecenas porttitor lacinia risus, et rhoncus felis vestibulum eget. Sed nec turpis nulla. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; In fringilla mollis leo sed auctor. </p> </div> </div> <div class="hideqst1"> <a id="sb0.9134.65" class="hideqst2" onclick="showHide('b0.9134.65')" href="javascript:void(0)"> Integer non urna vel ligula interdum?</a> </div> <div style="display:none;" id="b0.9134.65"> <!--This comment line added please dont remove this comment line--> <div class="hideAns"> <p>Suspendisse pretium gravida tortor, id blandit elit hendrerit porttitor. Mauris at purus id neque mollis placerat vitae in tortor. Morbi porta tincidunt sagittis. Nam quis augue justo, id euismod nisl.</p> <p>• Donec sit amet urna felis. Praesent at erat ligula, eget porttitor diam.<br> • Quisque quis sapien leo. Proin sit amet sem et lectus gravida iaculis a non turpis. Vivamus at metus quis odio mattis </p> </div> </div> </div> CSS code: Code: div.ws-webpart{margin-bottom:15px;clear:both;} .ws-webpart.hidecat1{padding-top:7px;} .ws-webpart.hidecat2{padding-left:2.2ex;color:#000;font-weight:700;text-decoration:underline;background:url(../images/layout/link_arrow.gif) no-repeat 0 3px;} .ws-webpart.hidecat3{padding-left:2.2ex;color:#000;font-weight:700;text-decoration:none;background:url(../images/layout/link_arrow_down.gif) no-repeat 0 3px;} .ws-webpart.collapseqst1{padding-top:7px;padding-left:2.2ex;} .ws-webpart.hideqst2{padding-left:2.2ex;color:#7C902C;padding-right:0;background:url(../images/layout/link_arrow.gif) no-repeat 0 3px; zoom:1;} .ws-webpart.hideqst3{padding-left:2.2ex;color:#7C902C;padding-right:0;background:url(../images/layout/link_arrow_down.gif) no-repeat 0 3px;} .ws-webpart.hideAns{color:#000;padding-left:4.4ex;padding-right:1.5ex;padding-top:7px;} Javascript code: Code: <script language="javascript" > // Function for Collapsible Link function showHide(ID) { if (document.getElementById(ID).style.display == "block"){ document.getElementById(ID).style.display = "none"; if(ID.charAt(0)=="a"){ document.getElementById("z"+ID).className="hidecat2"; } if(ID.charAt(0)=="b"){ document.getElementById("s"+ID).className="hideqst2"; } } else { document.getElementById(ID).style.display = "block"; if(ID.charAt(0)=="a"){ document.getElementById("z"+ID).className="hidecat3"; } if(ID.charAt(0)=="b"){ document.getElementById("s"+ID).className="hideqst3"; } } } </script> I have attached the images. Thanks in advance I'm creating a menu using html, css and a javascript, I found a tutorial to follow online. What I am trying to achieve is when the mouse hovers over the menu items, each item will have a different colour background. the problem is that i can do this but it only works with one colour and not different colours. this is the html: Code: <ul> <li><a href="1.php">Things</a></li> <li><a href="2.php">Animals</a> <ul> <li><a href="2-1.php">Cani</a> <ul> <li><a href="2-1-1.php">Domestic dogs</a></li> <li><a href="2-1-2.php">Wolves</a></li> </ul> </li> <li><a href="2-2.php">Felidae</a> <ul> <li><a href="2-2-1.php">Domestic cats</a></li> <li><a href="2-2-2.php">Wild cats</a></li> </ul> </li> </ul> </li> <li><a href="3.php">Humans</a></li> </ul> the css is as follows: Code: div#s1 { width: 200px; /* menu width */ } div#s1 ul { background-color: #036; list-style-type: none; /* get rid of the bullets */ padding:0; /* no padding */ margin:0; /* no margin for IE either */ } div#s1 ul li { margin: 0; padding: 0; background-color: #036; display:block; border-top: 1px solid white; /* lines */ } div#s1 ul li a { display: block; /* lines extend to right, make area clickable */ color: white; background-color: #036; padding: 3px 3px 3px 23px; margin:0; text-decoration: none; height:15px; /* hint for IE, alternatively remove whitespace from HTML */ } div#s1 ul ul li a { margin-left: 20px; /* indent level 1 */ } div#s1 ul ul ul li a { margin-left: 40px; /* indent level 2 */ } div#s1 ul ul ul ul li a { margin-left: 60px; /* indent level 3 */ } div#s1 li ul, div#s1 li.open li.closed ul { display: none; /* collapse */ } div#s1 li.open ul { display: block; /* expand */ } div#s1 ul li.open a { background-image: url(bullet_open.gif); background-repeat: no-repeat; } div#s1 ul li.closed a { background-image: url(bullet_closed.gif); background-repeat: no-repeat; } div#s1 ul li.leaf a { background-image: url(bullet_leaf.gif); background-repeat: no-repeat; } div#s1 li.active a { background-position: 0px -20px; color: red; /* highlight text */ } div#s1 li.active li a { background-position: 0px 0px; color: white; /* fix lower levels */ } div#s1 ul li a:hover { color: red; background-color: #06C; /* rollover effect */ } and finally the javascript: Code: var menu_active_class = "active"; var menu_leaf_class = "leaf"; var menu_open_class = "open"; var menu_closed_class = "closed"; //the default page that is displayed if URL ends in / var menu_default_page = "index.php"; var menu_url; //main function //menu_id : id of the element containing the navigation function menu_main(menu_id) { var url = location.href; if (url.lastIndexOf("/") == (url.length-1)) { url = url+menu_default_page; } if (url.lastIndexOf("?") >= 0) { url = url.substring(0, url.lastIndexOf("?")); } if (url.lastIndexOf("#") >= 0) { url = url.substring(0, url.lastIndexOf("#")); } menu_url = url; var main = document.getElementById(menu_id); if (!main) alert("No element with id '"+ menu_id +"' found"); menu_traverse(main); } /* Walks down the subtree and on the way back sets properties. returns bit set 1: set = element is a node, unset = element is a leaf 2: set = element contains the active node 4: set = element is the active A node */ function menu_traverse(element) { var props = 0; // walk down for (var i=0; i<element.childNodes.length; i++) { var child = element.childNodes[i]; props |= menu_traverse(child); // aggregate bits } // on the way back now switch (element.tagName) { case "UL": props |= 1; break; case "LI": var c1 = (props & 1) ? ((props & (2|4)) ? menu_open_class : menu_closed_class) : menu_leaf_class; element.className = element.className ? element.className+" "+c1 : c1; if (props & 4) { if (!(props & 2)) element.className += " "+menu_active_class; props |= 2; props &= 1 | 2; // reset bit 4 } break; case "A": if (props & 2) break; // once is enough var href = element.getAttribute("href"); if (menu_isSameUrl(menu_url, href)) props |= 4; break; } return props; } //matches two URIs when href is the last part of url //.. and . are correctly resolved function menu_isSameUrl(url, href) { var a = url.split(/[?\/]/i); var b = href.split(/[?\/]/i); var i = a.length - 1; var j = b.length - 1; while ((i >= 0) && (j >= 0)) { if (b[j] == "..") { j-=2; continue; } if (a[i] == "..") { i-=2; continue; } if ((b[j] == ".") || (b[j] == "")) { j--; continue; } if ((a[i] == ".") || (a[i] == "")) { i--; continue; } if (! (a[i] == b[j])) return false; i--; j--; } return true; } New to this forum but hope this will explain my problem, any help is much appreciated! thanks!! Jesper |