473,387 Members | 1,585 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Element Links

2
Hi.

How can I get all links for a specified element?

For example, how can I extract links from:

<td id="test">
<a href = "www.google.com">Google</a>
<a href = "www.yahoo.com">Yahoo</a>
</td>

Please help. Thanks in advance :)
Jun 2 '07 #1
3 1146
dmjpro
2,476 2GB
Hi.

How can I get all links for a specified element?

For example, how can I extract links from:

<td id="test">
<a href = "www.google.com">Google</a>
<a href = "www.yahoo.com">Yahoo</a>
</td>

Please help. Thanks in advance :)
Welcome to TSDN.

I m writing this code for IE, for others u ll try urself.

Expand|Select|Wrap|Line Numbers
  1. var TD_ref = document.getElementById("test");
  2. for(var i=0;i<TD_ref.children.length;i++)
  3. {
  4.    if(TD_ref.children[i].tagName == "a") //ur_code to do with the links.
  5. }
  6.  
Best of luck.

Kind regards,
dmjpro.
Jun 2 '07 #2
Mirek
2
thank you for your reply, but this doesn't work neither on firefox neither on IE:

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <title>getElementById example</title>
  4.  
  5. <script type="text/javascript">
  6.  
  7. function f1()
  8. {
  9.       var TD_ref = document.getElementById("id1");
  10.       alert("was here 1");
  11.       for(var i=0;i<TD_ref.children.length;i++)
  12.       {
  13.          if(TD_ref.children[i].tagName == "a") //ur_code to do with the links.
  14.           alert("was here 2");
  15.       }
  16. }
  17. </script>
  18. </head>
  19.  
  20. <body>
  21. <div id="id1"><a href ="http://www.google.com">Google</a></div>
  22. <button onClick="f1();">blue</button>
  23. </body>
  24. </html>
Jun 2 '07 #3
mrhoo
428 256MB
var atags=
document.getElementById('test').getElementsByTagNa me('a');

/*
atags returns a node list of <a> elements;
if you want to return an array of href's run a loop on atag's members:
*/
var A=[], tem;
var L= atags.length;

for(var i=0;i<L;i++){
tem=atags[i];
if(tem.href)A.push(tem.href);
}
//return A;
Jun 2 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: deko | last post by:
How to change a link's color based on a php variable? I have a number of links on a page: <p><a href="page1.php">Page 1</a></p> <p><a href="page2.php">Page 2</a></p> <p><a...
1
by: Wolfgang Lipp | last post by:
my question is: do we need container elements for repeating elements in data-centric xml documents? or is it for some reason very advisable to introduce containers in xml documents even where not...
0
by: Wolfgang Lipp | last post by:
From: Lipp, Wolfgang Sent: Tuesday, 27?January?2004 13:26 <annotation> the first eleven contributions in this thread started as an off-list email discussion; i have posted them here with...
1
by: Stanimir Stamenkov | last post by:
Here's an example: <form action="bogus" method="post"> <p> <a href="prev.cgi"><input type="submit" name="prev" value="< Back"></a> <a href="next.cgi"><input type="submit" name="next"...
3
by: Mark Tranchant | last post by:
On my site, I use a background image of a small arrow to denote links that lead away from my site. This page has four such links in the first section: http://tranchant.plus.com/notes/cable-wrap...
8
by: Adrienne | last post by:
The elements MENU and DIR were in the HTML 2.0 spec, and disappeared in 4. I would like to have them back, they makes sense. For example: <menu> <li>Home</li> <li>Contact</li> </menu> ...
1
by: kwicher | last post by:
Hi! I hope I will be able to escribe my problem clear enough. So I have the following definition in CSS file. #links { ...... } #links a { ........ }
4
by: Eric Lindsay | last post by:
Although http://www.w3.org/Style/LieBos2e/enter/ say "The title of a document does not show up on the canvas, so it is not affected by CSS styles", there is a note by Seamus P. H. Leahy on styling...
4
by: Miroslav Stampar [MCSD.NET / Security+] | last post by:
I need to get all links from an document element. In sample below how can i get link to "www.google.com" from element with ID="here" <html> <head> <title></title>
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.