Jump to content
  • Advertisement
Sign in to follow this  
FlashInThePan

Get href url in Javascript without id

This topic is 3158 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I need to be able to get href urls that lack an id, using javascript. Some example code
<script>
function showHref(elementID)
{
for(a = [[0]]; a < [[3]]; a++)
{
var q; 
//Somehow, make q get href values
alert(q.href);

}
}
</script>


<BODY>

<a href="http://www.mysite.com/main.htm?[[22]]" target="_blank">[[22]] page</a>
<a href="http://www.mysite.com/main.htm?[[59]]" target="_blank">[[59]] page</a>
<a href="http://www.mysite.com/main.htm?[[91]]" target="_blank">[[91]] page</a>

<input type=button value="get Href" onclick ="showHref('myLink');">

</BODY>

What would I need to add in the showHref function to get the urls? I tried using getattribute, and either I did it wrong, or it can't do what I want it to do.

Share this post


Link to post
Share on other sites
Advertisement
It's pretty fiddly to do this in "vanilla" javascript, but if you use a library like jQuery, it becomes trivial:

$("a").each(function() {
alert(this.href);
});

Share this post


Link to post
Share on other sites
I looked around for about 3 hours before coming here.

Both of these work great.
I guess I was in the right direction with getattribute, but not really there.
And this JQuery thing is cool. Reading some documentation now.

Looks like rating you both up only adds 2 points, so I guess there's not much there. You'll just have to accept my gratitude ;)
Thanks to you both.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!