2

How can i get the href from such a table?

<table class="file_slot" cellpadding=0 cellspacing=3>
<tr>*****************</tr>
<tr>
        <td><b>Size:</b></td>
        <td>452<small><a href="http://www.google.com">Google</a></small></td>
     </tr>

I tried using getElementsByClassName but i don't get to the <a> tag.

Thanks in advance

1
  • Thanks a lot guys for your quick answers. :) Commented Jul 15, 2013 at 10:39

3 Answers 3

5

You can do

var href =  document.querySelector('.file_slot a').href;
Sign up to request clarification or add additional context in comments.

3 Comments

Should be noted that, depending on what results are required, this could be slower than getElementsByTagName: jsperf.com/queryselectorall-vs-getelementsbytagname
@Blade0rz Obviously OP doesn't want all a elements but the one of his table. And this would still appear instantaneous for all practical purposes.
Indeed, but for the wider audience or the two people who upvoted the question, it may be applicable.
3

You want getElementsByTagName instead:

var aTags = document.getElementsByTagName("a");

Comments

2

Try

var file=  document.querySelector('.file_slot a');
file.href="http://www.google.com";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.