Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
|
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 24th, 2007, 08:14 AM
Friend of Wrox
 
Join Date: Sep 2004
Posts: 103
Thanks: 0
Thanked 0 Times in 0 Posts
Default how to get all <link> objects?

Hi all,

How shall I get all link tags in my page and then get their outerHTML or all their relevant attributes...the length of the collection returned from the code blow is always zero:

window.document.links;

what's the problem.

Best Regards,
Nerssi



 
Old January 24th, 2007, 09:28 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to vinod_yadav1919 Send a message via Yahoo to vinod_yadav1919
Default

Hii Nerssi!!
use
var allLinks = document.getElementsByTagName("a");.
e.g.
<script>
function getLink()
{
obj=document.getElementsByTagName('a')

for(i=0;i<obj.length;i++)
{
alert(obj[i].innerHTML)
//alert(obj[i].outerHTML)
}

}

</script>
<a href="#" onclick="getLink()">sdf</a>
<a href="a.html">sdf</a>
<a href="a.html">sdf2</a>
<a href="a.html">sdf3</a>
<a href="a.html">sdf4</a>
<a href="a.html">sdf5</a>

Hope this will help you


Cheers :)

vinod
 
Old January 27th, 2007, 03:54 AM
Friend of Wrox
 
Join Date: Sep 2004
Posts: 103
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Briliant trick!
Thanks vinod...






Similar Threads
Thread Thread Starter Forum Replies Last Post
setting combox box value to href in <link> bhairraju CSS Cascading Style Sheets 2 March 23rd, 2007 01:58 PM
<link> statement - compile failure to see bug VictorVictor BOOK: Beginning CSS: Cascading Style Sheets for Web Design ISBN: 978-0-7645-7642-3 1 April 18th, 2006 02:26 PM
<style> tags in a <body> vs. <div> bcat BOOK: Beginning CSS: Cascading Style Sheets for Web Design ISBN: 978-0-7645-7642-3 1 March 27th, 2005 08:50 AM
<marquee><b>About CHAT App. in PHP4</b></marquee> Ramkrishna PHP How-To 1 September 11th, 2004 07:01 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.