我有这个代码
<div onclick="location.href='www.example.com'">
  <!--Content Here-->
</div>
<div>
  <!--Content Here-->
</div>
我知道我可以为divwith使用内联 CSS 样式location.href来做类似的事情
<div onclick="location.href='www.example.com';" style="cursor:pointer;">
  <!--Content Here-->
</div>
虽然我宁愿不使用这种方法,因为内联样式以后更改起来很糟糕
我还可以添加一个div用于样式的类,例如
<div class="location" onclick="location.href='www.example.com';">
  <!--Content Here-->
</div>
.location {cursor:pointer;}
但我想知道是否有某种方法可以使用 CSS 仅div针对location.href. 我不能使用类似的东西div:first-child,因为我想使用外部样式表来设置这些样式,所以必须有一种方法只针对带有location.href. 如果不是纯粹的 CSS,有没有办法使用 jQuery 来做到这一点?