Solved

Display none for all links inside div

Posted on 2009-05-07
8
193 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 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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Suggested Solutions

Title # Comments Views Activity
Video Tutorial help 2 51
javascript delete path 7 45
sort Multi-dimensional array 6 45
How can I use javascript variable in mysql query 21 43
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

751 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