1

I'm trying to execute some changes on ALL anchor tags. Unfortunately, things aren't going as planned.

$('a').remove()

This line only seems to affect the first element it encounters--- if I execute it in the console repeatedly, it progresses through the page removing each new anchor it finds.

I want to remove them all at once. I had thought this select would affect them all. So then I tried:

$('a').each(function(){this.remove();});

And got:

TypeError: Object [object HTMLAnchorElement] has no method 'each'

What is the correct solution to this, to execute code on all anchors?

Ja͢ck
  • 170,779
  • 38
  • 263
  • 309
temporary_user_name
  • 35,956
  • 47
  • 141
  • 220

1 Answers1

6

It seems you haven't loaded jQuery correctly.

The console maps $ to document.querySelecor, which only finds the first item.


BTW, the console also maps $$ to document.querySelectorAll, so the following would work:

var allAnchors = $$('a');

You obviously won't have jQuery's methods available to allAnchors.

Joseph Silber
  • 214,931
  • 59
  • 362
  • 292