Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting href value of a link 2

Status
Not open for further replies.

Sarmx

Programmer
Jun 16, 2004
12
NL
Dear friends,

i am an asp developer with not much knowlage of javascript
my problem is the following:

i have a html table which every cell of it has
a link in it, how can i via javascript get access
to the href value of those links ( per cell)

i will be thankfull for every help

kind regards:
sarmx
 
well, that depends on how you want to access the object. let's say that you want the href for a specific link, which you've given an ID:

Code:
<a href="[URL unfurl="true"]http://www.google.com/"[/URL] id="myAnchor">Google</a>

You can quite simply retrieve the href by doing the following:

Code:
<script type="text/javascript"><!--

var a = document.getElementById('myAnchor');
alert( a.href );

//--></script>

If you want more specific information, you'll have to provide more specific information.



*cLFlaVA
----------------------------
[tt]( <P> <B>)13 * (<P> <.</B>)[/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 


Hey cLFlaVA, thanks very much for your help i think
you are very close to help me, but the problem is that
my links does not have any id or name
( so does not have anything like this: id="myAnchor")


think of something like this and i need to have
access to address1, address2 and address3 via javascript

Code:
<table id="MyCalendar">
  <tr>
    <td><a href="address1" title=" week1">firstweek</a></td>
    <td><a href="address2" title="29 mei">29</a></td>
    <td><a href="address3" title="30 mei">30</a></td>
 </tr>

</table>


so i have access to the cells in this way:

Code:
var RowWeek=document.getElementById('MyCalendar').rows[intRow].cells
 
var cellvalue = RowWeek[0].innerHTML

but i need to just have access to the href part

i would appreciate your further help.

thanks

sarmx

 
try this...

Code:
var RowWeek = document.getElementById('MyCalendar').rows[intRow].cells;
var anchor = RowWeek[0].getElementsByTagName("a")[0];
alert( anchor.href );

does that help you at all?



*cLFlaVA
----------------------------
[tt]( <P> <B>)13 * (<P> <.</B>)[/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Thanks very much cLFlaVA,

but it doesnt look like it is going to work!!

actualy i need to access the text in a cell rather than
the href,...the problem is that when i change the text
by innerHTML, it changes everything while i dont like to
change the href part,... so thats why i thought if i get
the href value first, i can later added again.

regards,

sarmx

 
>but it doesnt look like it is going to work!!
It doesn't look like it is going to work for your hidden agenda. Why do you out-witting our member's know-how? by not directly ask what you really want? I'm sure cLFlaVA would have answered in one-go rather than chasing a moving target.
[tt]
//quote
var RowWeek = document.getElementById('MyCalendar').rows[intRow].cells;
var anchor = RowWeek[0].getElementsByTagName("a")[0];
//unquote
alert(anchor.href + "\n" + anchor.innerHTML);
anchor.innerHTML="new text displayed";

[/tt]
 
Hey guys, I didnt mean to work in secrecy,
its just because I was deep into finding a solution
and had forgotten what the original plan was.

in the end i did excacty what i wanted and that is thanks
to you both

sarmx
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top