/    Sign up×
Community /Pin to ProfileBookmark

faq drop down

Hello

I’m a new kid and very amateur when it comes to javascript. I don’t seem to be able to get [URL=”http://javascript.internet.com/css/faq-drop-down.html”]Fang’s faq drop down script[/URL] to work! I’m following the instructions as closely as I can – looking at the comments from other users I’m not the first to encounter problems.

Any guidance gratefully received.

Thanks

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@BoarsHellApr 29.2008 — Where are you getting stuck? Can you post your code?
Copy linkTweet thisAlerts:
@MrNickauthorApr 29.2008 — Well I'm just cutting and pasting. So, as instructed, I'm putting the following in an external file named faqDropDown.js

function toggle(obj) {

// Moz. or IE

var sibling=(obj.nextSibling.nodeType==3)? obj.nextSibling.nextSibling : obj.nextSibling;

// hide or show

if(sibling.style.display=='' || sibling.style.display=='block') {

sibling.style.display='none';

obj.firstChild.firstChild.data='+';

}

else {

sibling.style.display='block';

obj.firstChild.firstChild.data='-';

}

}

//

function initCollapse() {

var oDT=document.getElementById('content').getElementsByTagName('dt');

for (var i=0; i < oDT.length; i++) {

oDT[i].onclick=function() {toggle(this)};

var oSpan=document.createElement('span');

var sign=document.createTextNode('+');

oSpan.appendChild(sign);

oDT[i].insertBefore(oSpan, oDT[i].firstChild);

oSpan.style.fontFamily='monospace';

oSpan.style.paddingRight='0.5em';

oDT[i].style.cursor='pointer';

toggle(oDT[i]);

}

oDT=null;

}



function addLoadEvent(func) {

var oldonload = window.onload;

if (typeof window.onload != 'function') {

window.onload = func;

} else {

window.onload = function() {

if (oldonload) {

oldonload();

}

func();

}

}

}



addLoadEvent(function(if(document.getElementById && document.createElement) {

initCollapse();

});



Then I'm putting the following into the <head> section of my HTML doc:



<script type="text/javascript" src="faqDropDown.js"></script>



Finally I'm putting the following into the <body> section:



<dl id="content">

<dt>This is Question #1 <em class="sm">[click here]</em></dt>

<dd>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in.<br><br></dd>

<dt>This is Question #2 <em class="sm">[click here]</em></dt>

<dd>Ma quande lingues coalesce, li grammatica del resultant lingue es plu simplic e regulari quam ti del coalescent lingues. Li nov lingua franca va esser plu simplic e regulari quam li existent Europan lingues. It va esser tam simplic quam Occidental: in fact, it va esser Occidental. A un Angleso.<br><br></dd>

<dt>This is Question #3 <em class="sm">[click here]</em></dt>

<dd>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in.</dd>

</dl>

</div>



But when I load the file into a browser it's just the whole lot static...
×

Success!

Help @MrNick spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...