var tab1 = $('.tabs a:first-child').attr('href');
alert(tab1);
.. 尽管同一页面上有两个 div.switch
,但仅匹配一个。第二个位于页面下方,而不是位于同一个父级中。
编辑:基本上我的问题是, :first-child 应该找到所有元素,但它只是在 :first 之后停止
最佳答案
$('.tabs').each(function() {
alert($('a:first-child', $(this)).attr('href'));
});
关于jquery - :first-child only matches the first,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5062634/