/    Sign up×
Community /Pin to ProfileBookmark

how to do that with DOM

<div name=”parent1″>
<div id=”child1″><a href=””>a</a>
<div id=”child1″></div>
<div id=”child2″></div>
<div id=”child3″></div>
</div>
<div id=”child2″><a href=””></div>
<div id=”child3″><a href=””></div>
</div>

<div name=”parent2″>
<div id=”child7″></div>
<div id=”child8″></div>
<div id=”child9″></div>
</div>

if I do:
document.getElementsByTagName(‘DIV’);
i’ll get 11 DIV elements, but I wanna get just only 6 DIVs from ‘parent1’

sth like:
var c = document.getElementsByName(‘parent1’);
and next sth like: document.getElementsByName(‘div’) from c

Hope, you know what I wanna get ?
Can anybody help me?

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@Gozzy82Mar 11.2010 — var c = document.getElementsByName('parent1')[0]; //returns an array

var only6DIVsfromparent1 = c.getElementsByTagName('div');
Copy linkTweet thisAlerts:
@FangMar 11.2010 — [I]name[/I] is an invalid attribute for div, use [I]id[/I].
×

Success!

Help @rozpalacz 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.25,
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,
)...