Link to home
Start Free TrialLog in
Avatar of hankknight
hankknightFlag for Canada

asked on

Display none for all links inside div

Using JavaScript I want to make all links inside <div id="foobar"> display: none

var els = document.getElementsByTagName("a");
for (var i=0; i<els.length; i++) {
    if (els[i].parentNode____has_id___submenu {
        els[i].display.none;
    }
}

Open in new window

Avatar of alien109
alien109
Flag of United States of America image

try

 els[i].stye.display = "none";
ASKER CERTIFIED SOLUTION
Avatar of alien109
alien109
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of hankknight

ASKER

I know that!

What I don't know if how to test if the parent id = foobar


I need this line fixed:
         if (els[i].parentNode____has_id___submenu {
why do you need to test that?

if you get the foobar element by id. then get all of the link elements which are descendants of that, there is no need to test for that condition since you already know they are descendants of the foobar element.
SOLUTION
Avatar of HonorGod
HonorGod
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hank, thanks for the grade & points, but I think that alien109 deserves them because he did the referenced update.

Please "request assistance" with this question, and give alien109 all the points.

Thanks
Thanks Hank for taking the time, and making the effort to reward alien109.

Thanks for the assist, and the points.

Good luck & have a great day.