/    Sign up×
Community /Pin to ProfileBookmark

DOM question

Hey guys, just a quick question…

To reference the anchors in an HTML document, I know that I use document.anchors

However, what do I do to reference the DIVs and the SPANs that I have in my page? Is there an array that is automatically created for those, also? Thanks a ton for your help!

-jinkas

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@VladdySep 26.2003 — document.body.getElementsByTagName(tagName) will return the array of elements which have a specified tag.
Copy linkTweet thisAlerts:
@jinkasauthorSep 26.2003 — [i]Originally posted by Vladdy [/i]

[B]document.body.getElementsByTagName(tagName) will return the array of elements which have a specified tag. [/B][/QUOTE]


So I would use something like this?:

divArray = document.body.getElementsByTagName(div);

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

divArray[i].style.visibility = "visible";

}
Copy linkTweet thisAlerts:
@VladdySep 26.2003 — tagName is a string, so the it should be .getElementsByTagName('div');
Copy linkTweet thisAlerts:
@jinkasauthorSep 26.2003 — Right. Thanks a ton for your help!
×

Success!

Help @jinkas 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.18,
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,
)...