Solved

Display none for all links inside div

Posted on 2009-05-07
8
182 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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
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…

707 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now