【问题标题】:how to find first row first anchor tag in jquery?如何在jquery中找到第一行第一个锚标记?
【发布时间】:2026-01-03 11:55:02
【问题描述】:

我正在尝试在 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'})
})

但无法找到正确的元素。

【问题讨论】:

  • 能否分享完整的html
  • 在它存在的链接中
  • 你能在这里分享吗? jsbin 在我的网络中不起作用

标签: javascript jquery jquery-selectors


【解决方案1】:

$('a[title=" Nominal"]')[0] 返回 element 的 DOM 对象,而不是 jquery 对象。由于这个.css () 方法没有应用更改。

你应该使用.eq()选择器通过它的索引来获取元素的jquery对象:

 $('a[title=" Nominal"]:eq(0)').css({'background-color':'red'});

使用 Javascript:

document.querySelectorAll('a')[0].style.backgroundColor = 'red';

Working Demo

【讨论】:

  • 正确答案。我们可以使用pure javascript 使用queryselector 吗??
  • 有可能吗??
最近更新 更多