Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery each div problem

Tags:

html

jquery

each

I need to obtain all the divs with a given id but the jquery each function only obtain the first one.

Example:

<div id="#historial">some html code</div>
<div id="#historial">some html code</div>
<div id="#historial">some html code</div>
<div id="#historial">some html code</div>

script:

$("#historial").each(function() {
alert("one div");
});

if I pass a anchor o a id + anchor ej $("#lala a") it's works ok.

What's wrong?

BR

like image 268
Santiago Avatar asked Dec 01 '22 06:12

Santiago


1 Answers

You can only use a specific id for one element in a page. Use a class instead:

<div class="historial">some html code</div>
<div class="historial">some html code</div>
<div class="historial">some html code</div>
<div class="historial">some html code</div>

$(".historial").each(function(e) {
  alert("one div");
});
like image 73
Guffa Avatar answered Dec 03 '22 23:12

Guffa