Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Display none for all links inside div

Posted on 2009-05-07
8
Medium Priority
?
205 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1800 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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 200 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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'…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

718 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