views:

100

answers:

5

Is there anyway I can get all of the <a> in a page, I want to apply a new targets to all of them.

A: 

If I recall correctly, the prototype library has something like this...

Justin
+1  A: 

if you're using jQuery:

$("a").attr("target","_blank")
Jason
i'm ok with you giving the jQuery solution as long as you give the non-jQuery solution as well. unless the asker mentions jQuery, jQuery should not be used as the main answer.
geowa4
it was just a suggestion. i was providing help that i knew.
Jason
+12  A: 

You can use

document.links

or in jQuery

$('a')

or in DOM

document.getElementsByTagName('a')
Greg
+1 comprehensive; maybe add some help for modifying targets, even though it wasn't specifically asked for?
geowa4
A: 

I believe this will do what you need:

document.getElementsByTagName("A");
John MacIntyre
A: 

Using purely Javascript DOM:

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

You can check out reference at: http://www.javascriptkit.com/domref/elementmethods.shtml

Guilherme