/    Sign up×
Community /Pin to ProfileBookmark

Hide <dd> onLoad

I have the following line in my HTML document:

[code]<body onLoad=”hideDD()”>[/code]

This is the function in an external JavaScript file linked in the header:

[code]function hideDD()
{
var dd = document.getElementsByTagName( ‘dd’ );
dd.style.position = ‘absolute’;
dd.style.left = ‘-9000px’;
}[/code]

I would appreciate any help with this little script. I am probably missing something glaringly obvious.

Thanks.

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@scragarAug 04.2008 — PHP forum tags used for pretty colour
[code=php]window.onload = function(){
var dd = document.getElementsByTagName('dd');
for(var i = dd.length-1; i>0; i--){
dd[i].style.position = 'absolute';
dd[i].style.left = '-9000px';
};
};[/code]


getElementsByTagName returns an array, not a single element. loop through and style each one.
Copy linkTweet thisAlerts:
@KorAug 04.2008 — Watch out:
<i>
</i>for(var i = dd.length-1; i&gt;[COLOR="Blue"]=[/COLOR]0; i--){
Copy linkTweet thisAlerts:
@fortehwebauthorAug 04.2008 — Thanks for the info. Didnt know that about getElementsByTagName.

The solution you gave works, only for some reason it doesnt hide the first occurance of <dd> in the page, which remains displayed.

Any other ideas?
Copy linkTweet thisAlerts:
@fortehwebauthorAug 04.2008 — Watch out:
<i>
</i>for(var i = dd.length-1; i&gt;[COLOR="Blue"]=[/COLOR]0; i--){
[/QUOTE]


GENIUS. Well spotted.

Thanks all.
×

Success!

Help @fortehweb 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.28,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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