jquery每个div问题

标签 jquery html each

我需要获取所有具有给定 id 的 div,但 jquery 每个函数只获取第一个。

例子:

<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>

脚本:

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

如果我传递一个 anchor o a id + anchor ej $("#lala a") 它工作正常。

怎么了?

BR

最佳答案

您只能为页面中的一个元素使用特定的 ID。改用类:

<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");
});

关于jquery每个div问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2082991/

相关文章:

jquery - 编写此代码的更好方法? jQuery

javascript - 使用 jQuery 将 SVG 元素插入到 HTML 标记中

javascript - 如何在 Jquery 中循环播放动画

jquery - 带有动画的滚动顶部不起作用

html - 减少 FontAwesome 中的字体和圆圈大小

javascript - Accordion 滚动问题 - 滚动到事件 Accordion 的顶部

jquery - 如何添加编号从 4 开始的类

javascript - 当用户多次单击按钮时,将 AJAX 请求的数量限制为一个

javascript - Isotope- fitColumns with height auto on items

html - 使输入范围 slider 占用所有可用空间