jimfraser,
Your show and hide script works great now winthin my CMS as long as I upload the javascript as part of the content. I know this is not the best practice, but it works.
Now onto more challenges. My Designer wants me to style it in such a way that:
a) The "show" & "hide" is part of an h4 header,
b) Instead of "show" the link says "read more..." as part of the header
c) An image (circle with arrow) points to the words "read more.." when the content is hidden and points downward when the hidden part is displayed.
Here is my javascript and mark-up so far. My questions are below.
HTML Code:
<script type="text/javascript">
function showHide(link) {
var theDiv = link.parentNode.getElementsByTagName("div")[0]; // this gives us a reference to the div that contains the text we want to hide/show
if (link.innerHTML == "Show") {
// we need to show the div
theDiv.style.display = "";
link.innerHTML = "Hide";
} else {
// we need to hide the div
theDiv.style.display = "none";
link.innerHTML = "Show";
}
}
</script>
<div class="elena_additionalInfo">
<h4 style="display:inline">Yoga and fulfillment</h4> <img src="/images/nav/dot_wi_arrow.gif" alt="go" class="circ_ctr" /> <a href="nojavascript.html" onclick="showHide(this);return false;">Show</a>
<div style="display:none;">
<br />
<p>Human beings want to live fully. We feel an inner urge to create, to love, to express, to master the complexities of life-to feel fulfilled in and by our lives...</p>
</div>
</div>
Concerning a) The "show" & "hide" is part of an h4 header:
The script would not work when the line:
HTML Code:
<h4>Yoga and fulfillment <img src="/images/nav/dot_wi_arrow.gif" alt="go" class="circ_ctr" /> <a href="nojavascript.html" onclick="showHide(this);return false;">Show</a></h4>
was incorporated entirely within an h4 tag. That's why I made the h4 come at the head of the line (as in the first script above) and then switched its display to "inline." This seems to work. I can also style the "Show" similarly within the link.
Concerning b) Instead of "show" the link should say "read more..." as part of the header
I have tried to style "Show" and "Hide" withing the JavaScript without success. Any styles I apply break the script. Question: Is there some way to use "read more..." and "hide" styled like my h4 without breaking the script.
Concerning c) An image (circle with arrow) should point to "read more.." and point downward when the hidden part is displayed.
I have two .gifs, one of the arrow pointing to the right and one pointing down. How can I get these to replace one another depending on the state of the show and hide?
Bookmarks