[英]how to find first row first anchor tag in jquery?
我想在 jquery 中找到第一行第一个锚标签?
我有4
行。我想获得first row
锚标记。 我试过这样
https://jsbin.com/woxatuxoju/edit?html,js,output
$(()=>{
console.log( $('a[title=" Nominal"]')[0])
$('a[title=" Nominal"]')[0].css({'background-color':'red'})
})
但无法找到正确的元素。
$('a[title=" Nominal"]')[0]
返回元素的 DOM object 而不是 jquery object。 由于这个.css ()
方法没有应用更改。
您应该使用.eq()
选择器通过索引获取元素的 jquery object :
$('a[title=" Nominal"]:eq(0)').css({'background-color':'red'});
使用 Javascript:
document.querySelectorAll('a')[0].style.backgroundColor = 'red';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.