[英]How to get attributes of individual elements in jquery array
我正在使用$(".drawer-face")
在jquery中獲取元素數組
如果我使用$(.drawer-face")[x]
, .drawer-face
得到x元素,其中包含.drawer-face
返回給我。
我希望能夠檢查x元素內的屬性,但是我得到了
當我使用$(".drawer-face").[6].attr("title")
, Uncaught TypeError: $(...)[6].attr is not a function at <anonymous>:1:22
$(".drawer-face").[6].attr("title")
例。
$(".drawer-face").eq(x).attr(...)
使用eq(#)
方法將元素保留為jQuery對象。
var $drawers = $('.drawer-face'); console.log( $drawers.eq(2).attr('title') );
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <a href="#" class='drawer-face' title="title 1">Title 1</a> <a href="#" class='drawer-face' title="title 2">Title 2</a> <a href="#" class='drawer-face' title="title 3">Title 3</a> <a href="#" class='drawer-face' title="title 4">Title 4</a> <a href="#" class='drawer-face' title="title 5">Title 5</a>
您可以這樣:
$($(".drawer-face")[6]).attr("title")
$(".drawer-face")[6]
提供html dom和jQuery .attr()
不能在
您可以將JS和jQuery一起使用
$(".drawer-face")[6].getAttribute("title");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.