Undisclosed
07-23-2012, 11:39 AM
I have a problem with this code.
The spoiler only expands if I click on its title (text). What I want to happen is for it to expand if I click the whole div (header) itself.
I tried different methods but it always ends in failure.
It's either clicking the div makes the header itself disappear, or clicking any headers makes only the first spoiler to expand.
<style type="text/css">
body,input{font-family:"Trebuchet ms",arial;font-size:12px; }
.spoiler{ background: #691816; border:1px solid #441f1e; padding-left:10px; border-radius: 3px; margin-bottom: 4px; box-shadow: 0 0 5px 2px #888; color: #fff;}
.spoiler:hover{background: #7d1e1a;}
.spoiler .inner { background: #fff; margin-left:-10px; color: #000;}
.spoiler .h2 {color: #eee; text-decoration:none; align:right; cursor: pointer;}
</style>
<script type="text/javascript">
function showSpoiler(obj)
{var inner = obj.parentNode.getElementsByTagName("div")[0];if (inner.style.display == "none")
inner.style.display = ""; else inner.style.display = "none";}
</script>
<div class="spoiler"">
<a type="button" onclick="showSpoiler(this);" class="h2">Testing</a>
<div class="inner" style="display:none;">
test</div>
</div>
<div class="spoiler"">
<a type="button" onclick="showSpoiler(this);" class="h2">Testing2</a>
<div class="inner" style="display:none;">
test2</div>
</div>
The spoiler only expands if I click on its title (text). What I want to happen is for it to expand if I click the whole div (header) itself.
I tried different methods but it always ends in failure.
It's either clicking the div makes the header itself disappear, or clicking any headers makes only the first spoiler to expand.
<style type="text/css">
body,input{font-family:"Trebuchet ms",arial;font-size:12px; }
.spoiler{ background: #691816; border:1px solid #441f1e; padding-left:10px; border-radius: 3px; margin-bottom: 4px; box-shadow: 0 0 5px 2px #888; color: #fff;}
.spoiler:hover{background: #7d1e1a;}
.spoiler .inner { background: #fff; margin-left:-10px; color: #000;}
.spoiler .h2 {color: #eee; text-decoration:none; align:right; cursor: pointer;}
</style>
<script type="text/javascript">
function showSpoiler(obj)
{var inner = obj.parentNode.getElementsByTagName("div")[0];if (inner.style.display == "none")
inner.style.display = ""; else inner.style.display = "none";}
</script>
<div class="spoiler"">
<a type="button" onclick="showSpoiler(this);" class="h2">Testing</a>
<div class="inner" style="display:none;">
test</div>
</div>
<div class="spoiler"">
<a type="button" onclick="showSpoiler(this);" class="h2">Testing2</a>
<div class="inner" style="display:none;">
test2</div>
</div>