Page is a not externally linkable
- Code, Content, and Presentation
-- JavaScript and AJAX
---- Hide and Display Div


matthewamzn - 7:12 pm on Mar 10, 2009 (gmt 0)


I'm making an faq page. When someone clicks on a question I want the answer to appear below it. This is what I've got so far, but it's not changing the style on click:

<script>
function displayAnswer($id) {
var status = document.getElementById($id).getAttribute("style");
if (status === "display:none;") {
document.getElementById($id).setAttribute("style","display:block;");
} else {
document.getElementById($id).setAttribute("style","display:none;");
}
}
</script>

This is the affected php code:
echo "<a href='javascript:displayAnswer({$faq[faq_id]});'>{$faq[question]}</a><br/>";
echo "<div id='{$faq[faq_id]}' style='display:none;'>{$faq[answer]}<br/></div>";


Thread source:: http://www.webmasterworld.com/javascript/3867396.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com