[英]How to add an attribute to an image with a specific class or alt text js/jquery?
我需要使用JS或jQuery为特定图像添加属性,但我无法弄清楚。
我正在使用 WordPress,我想要添加属性的图像在 slider 中,因此我无法向这些图像添加任何 class。
我试图通过使用容器 class 来查找图像来添加我想要的属性,但它没有用。
$('.dce-img > img').attr('rlskip', '1');
这就是我想要的样子:
<div class="dce-item">
<figure data-image-ratio="0.5" class="dce-img dce-fit-img">
<img src="../img/F4D13DA3-5351-4F69-8C33-0A1EF3BFDF67.webp" alt="Demo_ts_2" rlskip="1">
</figure>
</div>
你能帮我找到解决办法吗? 我必须在这里为 slider 的图像添加rlskip
属性。
问题是$
没有定义。 将$
更改为jQuery
,如下所示:
jQuery('.dce-img > img').attr('rlskip', '1');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.