Wrox Programmer Forums
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript 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 November 10th, 2005, 02:31 PM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 139
Thanks: 0
Thanked 0 Times in 0 Posts
Default href

Hi,

How do you access the href of a link? Say I ahve this table (which will have a lot more links)... how do I get the bloody '#'???

function linkTest()
{
    tables = document.getElementsByTagName("table");
    var table = tables.item(2);
    var rows = table.getElementsByTagName("tr");
    row = rows.item(0);
    var cells = row.getElementsByTagName("td");
-> alert (cells.item(0).innerHTML.href);
}

<table>
    <tr>
        <td><a href="#" onClick="linkTest();">Test</a></td>
    </tr>
</table>

 
Old November 10th, 2005, 02:37 PM
Friend of Wrox
 
Join Date: Jun 2004
Posts: 449
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to r_ganesh76
Default

it should be
     cells.item(0).href
insted of
     cells.item(0).innerHTML.href

innerHTML is string and it doesnt have an href property on the otherhand, item(0) is an object whcih is an anchor which in turn has a property by the name href

Regards
Ganesh
 
Old November 20th, 2005, 10:59 AM
Registered User
 
Join Date: Nov 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to prasanth_vijayawada
Default

hi,

Use this code to work...in I.E atleast :-)

var cells=row.getElementsByTagName("td");

var txt=cells.item(0).getElementsByTagName("a");

alert(txt.item(0).href);






Similar Threads
Thread Thread Starter Forum Replies Last Post
using href in xslt rajesh_css XSLT 0 September 18th, 2008 02:44 AM
REGEX to get href="#" monfu BOOK: Beginning Regular Expressions 2 July 24th, 2008 11:46 AM
Chapter 8, href and HRef (p. 285) roman BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 2 June 16th, 2008 10:40 AM
href in xslt rahulsk1947 XSLT 2 May 18th, 2007 07:39 PM
Urgent please HREF mikedeepak HTML Code Clinic 2 September 26th, 2005 08:17 AM





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