| | |
make div appear when you click a link
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: May 2009
Posts: 74
Reputation:
Solved Threads: 1
ok. i am having trouble with this code:
when you click the link, it gets the id from the info provided in the link and makes it disappear (thats how its supposed to work). but it doesn't do that. i have seen the same code work on an different site.
thanks,
billy
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<head> <script type="text/javascript"> <!-- function switchPic(picID) { document.getElementById(picID).style.display="none"; } //--> </script> </head> <body> <a href="" onclick="switchPic(_1)">Click Here</a> </body>
when you click the link, it gets the id from the info provided in the link and makes it disappear (thats how its supposed to work). but it doesn't do that. i have seen the same code work on an different site.
thanks,
billy
Assuming you have this div in your page, initially set as div1 for its id.
it seems that your created function is used for hiding images.
Anyway you can easily create another function that will handle element's inside your page (showing/hiding).
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<div id="div1">Link 1</div> <a href="javascript:void(0);" onclick="showPic('div1');">Hide Div</a>
Anyway you can easily create another function that will handle element's inside your page (showing/hiding).
Last edited by essential; May 11th, 2009 at 12:21 am.
Here's a little demo that will show different div's depending on what link's you will click.
javascript Syntax (Toggle Plain Text)
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Script-Type" content="text/javascript" /> <meta http-equiv="Content-Style-Type" content="text/css" /> <title>Page Template</title> <meta name="author" content="DANI-USER : essential" /> <style type="text/css"> /* <![CDATA[ */ html, body { background-color : #f0f0f0; border : none; color : #696969; font : normal normal normal 90%/1.6 Verdana, Tahoma, Helvetica, Arial, sans-serif; height : auto; min-height : 600px; min-width : 800px; text-align : center; vertical-align : baseline; width : auto; } h2 { background-color : #ccc; border-bottom : 1px solid #708090; border-top : 1px solid #708090; font : 700 160% "Bernard MT Condensed"; line-height : 2ex; margin-top : 0; min-height : 2ex; padding : .100em 0em .100em 1em; white-space : nowrap; } div { border : none; margin : 0%; padding : 0%; } div#main { margin : 0% auto; text-align : left; height : 100%; overflow : hidden; width : 98%; } div.show { border : 2px solid; margin-bottom : .200em; padding : .300em; background-color : #fff; font : 700 160% Verdana, Arial, sans-serif; width : auto; } div.tube { border : 1px solid #ccc; height : 600px; margin : 1% auto 1% auto; padding : 1.200em; } .hide { display : none; } .show { display : block; } /* ]]> */ </style> <script type="text/javascript"> // <![CDATA[ var showElem; showElem = function( showID ) { div = (( document.getElementById ) ? document.getElementById( showID ) : document.all[ showID ] ); try { div.className = (( div.className === "hide" ) ? "show" : "hide" ); } catch( e ) { div.style.display = (( div.style.display === "none" ) ? "block" : "none" ); } }; // ]]> </script> </head> <body> <div id="main"> <div class="tube"> <h2>JavaScript Live DEMO!</h2> <div id="div1" class="hide">DIV 1</div> <div id="div2" class="hide">DIV 2</div> <div id="div3" class="hide">DIV 3</div> <p> <!-- First Format --> <a href="javascript:void(0);" onclick="showElem('div1');">Show DIV 1</a><br /> <!-- Second Format --> <a href="javascript:void(showElem('div2'));">Show DIV 2</a><br /> <a href="javascript:void(0);" onclick="showElem('div3');">Show DIV 3</a><br /></p> </div> </div> </body> </html>
Last edited by essential; May 11th, 2009 at 1:31 am.
![]() |
Similar Threads
- how to make div id's unique (JavaScript / DHTML / AJAX)
- When i log on to my site and click a link in it. It is logging out automatically (PHP)
- EXECryptor software protection (C)
- Personal Blogs...? (DaniWeb Community Feedback)
- Dummy asks: how can i? (PHP)
- Hide all DIV's On Click (JavaScript / DHTML / AJAX)
- Click the link and make me rich (Geeks' Lounge)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Help on showing div tag on the browser
- Next Thread: Moving div Background Position on Click
| Thread Tools | Search this Thread |
acid2 ajax ajaxexample ajaxjspservlets array beta browser captchaformproblem cart checkbox child class close codes column css date debugger decimal dependent design disablefirebug dom download editor element embed engine enter error events explorer ext file firefox focus form forms frameworks getselection google gwt gxt hiddenvalue highlightedword hint html ie7 ie8 iframe index internet java javascript javascripthelp2020 jquery jsf jsfile jsp jump libcurl listbox maps masterpage math media menu mp4 object onmouseoutdivproblem onmouseover onreadystatechange parent paypal pdf php position post problem programming prototype redirect runtime safari scale scriptlets scroll search security select shopping size software toggle unicode w3c web windowofwords wysiwyg \n





