将匹配元素的集合减少到集合中的第一个
xiyuetaCSS().first()属性方法,一种调用方式:
1、xiyuetaCSS("div").first(); //将匹配元素的集合减少到集合中的第一个,等同于 .eq(0)
总结:.first()用法与jQuery中jQuery().first()用法保持一致
see https://api.jquery.com/first
尝试一下>>
<script src="https://www.xiyueta.com/js/xiyueta.min.js"></script> <script>
xiyuetaCSS().parse("div{color:red}div{color:blue}div{color:green}"); $.log( xiyuetaCSS(" div ").first().html() )
</script>
div{color:red}