views:

74

answers:

2

I have two buttons with the same ID:

<button type="submit" onclick="//do something" id="theID">button 1</button>

<button type="submit" onclick="//do something" id="theID">button 2</button>

I would like to click both the buttons using prototype. So far I've tried the following but it doesn't work.

$('theID').each(function(item) { 
   item.click();
});

How can I easily click both buttons using prototype?

+2  A: 

I would say that the same id is a bad idea in general. It is incorrect syntax, as an elements id must begin with a letter and can only be given to one element.

You cannot have two elements with the same id.

Tom
+4  A: 

I have two buttons with the same ID

There's the problem. Use classes instead of IDs; by design and definition IDs must be unique. Stuff just plain won't work if they aren't.

$('.clickable').each(function(item) { 
   item.click();
});

And

<button type="submit" class="clickable">button 1</button>

<button type="submit" class="clickable">button 2</button>
Rex M
Prototype's CSS selector function is `$$`, `$` is only for `id || element`
CMS