473,779 Members | 1,992 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Element Links

2 New Member
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 1161
dmjpro
2,476 Top Contributor
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 New Member
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 Contributor
var atags=
document.getEle mentById('test' ).getElementsBy TagName('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.p ush(tem.href);
}
//return A;
Jun 2 '07 #4

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

Similar topics

7
6013
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 href="page3.php">Page 3</a></p> <p><a href="page4.php">Page 4</a></p> I want the link to be red if $nav has a value that corresponds to the page
1
2228
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 strictly needed? how can a recommendation on this in the light of existing tools like w3c xml schema and relaxng as well es established practice be answered? i would greatly appreciate any words, pointers, and links. the exposition of the...
0
625
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 the consent of their authors. </annotation>
1
8328
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" value="Next >"></a> </p> </form>
3
5632
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 The links are coded thus: <a class="external" href="url">blah</a>
8
1665
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> Perhaps speech enabled user agents could react accordingly, perhaps say
1
2766
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
19728
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 the title element in CSSPlay http://moronicbajebus.com/wordpress/wp-content/cssplay/title-display/ When I tried this to add a background image, the Jigsaw validator http://jigsaw.w3.org/css-validator/validator-upload didn't complain. The CSS I...
4
23820
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
9474
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10305
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10137
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9928
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8959
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7483
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6724
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4037
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2867
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.