匹配整个文档的第一个元素?

编程入门 行业动态 更新时间:2024-10-14 12:28:43
本文介绍了匹配整个文档的第一个元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想匹配整个文档中的第一个H1元素。不过,现在我面临的一个问题。

I want to match the first H1 element in my whole document. However, right now I'm faced with a problem.

我用下面的CSS选择器:

I'm using the following CSS selector:

h1:first-child { ... }

但是,它匹配页面上的几个H1标记。我怎样才能使它只匹配第一个?

However, it matches several H1 tags on the page. How can I make it match only the first one?

推荐答案

您允许使用jQuery作弊?某些时候的jQuery(JavaScript的)提供(S)超出了HTML和CSS的局限性优雅的替代品

are you allowed to cheat with jQuery? some times jQuery (javascript) provide(s) elegant alternatives beyond the html and css limitations

$(document).ready(function() { $('body').find('h1:first').css('color','#0000ff'); }); // ready

更多推荐

匹配整个文档的第一个元素?

本文发布于:2023-11-25 10:40:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1629429.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:第一个   元素   文档

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!