Hey everyone, The title may be a bit confusing, so let me explain. My goal is to have a div appear below another div based upon the id used. Now there will be multiple of these, so I need the JS function to be reusable. Currently I have the HTML like so:
<!DOCTYPE html><html><head> <meta charset="utf-8"> <title>LED</title> <link rel="stylesheet" href="css/layout.css" type="text/css" media="screen" charset="utf-8"> <script src="js/script.js" charset="utf-8"></script></head><body> <div id="pageWrap"> <div class="row" id="row1">Row (<a href="#" onclick="hideShow(this)">Show Info</a>)</div> <div class="row" id="row2">Row (<a href="#" onclick="hideShow(this)">Show Info</a>)</div> <div class="row" id="row3">Row (<a href="#" onclick="hideShow(this)">Show Info</a>)</div> <div class="row" id="row4">Row (<a href="#" onclick="hideShow(this)">Show Info</a>)</div> <div class="info" id="info1">Info</div> <div class="info" id="info2">Info</div> <div class="info" id="info3">Info</div> <div class="info" id="info4">Info</div> </div></body></html>
the CSS like so:
body {padding: 0;margin: 0;border: 0;width: 100%;height: 100%;font-size: 100%;font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif;}h1,h2,h3,h4,h5,h6,p {color: #000000;}h4,p {font-size: 1em;}#pageWrap,.row,.info {width: 900px;margin: 0 auto;}.row,.info {width: 225px;float: left;}.info {display: none;}
and the JS like so:
function hideShow(a) {var element = a.parentNode.nextSibling;while (element.className != 'info') {element = element.nextSibling;}element.style.display = element.style.display == 'block' ? 'none' : 'block';a.innerHTML = a.innerHTML == 'Show Info' ? 'Hide Info' : 'Show Info';}
Now as you will notice I have each Row id numbered, and each Info id numbered, along with that the Info divs fit under the Row divs. What I would like is if I hit Row1 it will show Info1, if I hit Row2 it will show Info2, etc. I could achieve this by creating a new JS function for each use, but that would be a waste. Any ideas how to automate this with one single function? Also if you have any ideas of how to keep the placement of the Info divs while still hiding it, that would be appreciated as well. Honestly though I think I could eventually figure that one out, still need the help with the JS though. Thanks for the help. P.S. I am still learning JS, once I get this down I won't need to ask for such noobie questions.