How to give the same link to several buttons automatically generated with the same ID

advertisements

How to give the same link to multiple auto-generated buttons with the same ID?

I've tried, but it only gives the first button the link, the rest of the buttons remain empty

$('#Button').click(function() {
    window.location='aaa.html';
});


In HTML there can be only one element with given ID, to assign the same jQuery code to multiple elements you should use "class" attribute instead.

See: http://www.w3.org/TR/html401/struct/global.html#h-7.5.2

JS:

$('.button').click(function() {
                    window.location='aaa.html';
                    });

HTML:

<div class="button">DIV 1</div>
<div class="button">DIV 2</div>
<div class="button">DIV 3</div>