Solved

Display none for all links inside div

Posted on 2009-05-07
8
186 Views
Last Modified: 2012-05-06
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

0
Comment
Question by:hankknight
  • 3
  • 3
8 Comments
 
LVL 12

Expert Comment

by:alien109
ID: 24329219
try

 els[i].stye.display = "none";
0
 
LVL 12

Accepted Solution

by:
alien109 earned 450 total points
ID: 24329247
var div = document.getElementById("foobar");
var els = div.getElementsByTagName("a");
for (var i=0; i<els.length; i++) {
    els[i].stye.display = "none";
}
0
 
LVL 16

Author Comment

by:hankknight
ID: 24329255
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 {
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 12

Expert Comment

by:alien109
ID: 24329304
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.
0
 
LVL 41

Assisted Solution

by:HonorGod
HonorGod earned 50 total points
ID: 24329683
Hank,
  Take another look at the code in http://#a24329247, the first lookup finds the "foobar" div.  The next only locates anchor tags within this div.
0
 
LVL 41

Expert Comment

by:HonorGod
ID: 24366695
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
0
 
LVL 41

Expert Comment

by:HonorGod
ID: 24368125
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.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question