Dudul
Dudul

Reputation: 87

Replace all divs with value

I have the following code:

$('#select_albums').load(document.location.href + "&action=get_albums");

But this is only replacing only the first found div with the id #select_albums from DOM. How do I replace all divs with an id?

Upvotes: 1

Views: 193

Answers (4)

Eric
Eric

Reputation: 97571

ids must be unique

Upvotes: 1

Alistair
Alistair

Reputation: 1326

id's must be unique, try using a class instead such as $(".albums").load...

Upvotes: 1

Daff
Daff

Reputation: 44205

Yes because by definition an element ID can only appear once on a page. If you have more elements use a class instead.

$('.select_albums').load(document.location.href + "&action=get_albums");

With

<div class="select_albums"></div>
<div class="select_albums"></div>

Upvotes: 1

kgiannakakis
kgiannakakis

Reputation: 104168

Every item in the DOM has a unique id. If you want to act on many divs at the same time use a class $(".myclass") or a tag $("div") selector.

Upvotes: 5

Related Questions