getElementsByClassName与jquery [英] getElementsByClassName vs. jquery
本文介绍了getElementsByClassName与jquery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我原来的功能是:
document.getElementsByClassName('blah')[9].innerHTML = 'blah';
...我如何更改,以便在jquery中获得相同的项目?我有这个,但是当我把'[9]'放在最后它不起作用时:
...how would I change that so I get that same item in jquery? I have this, but when I put '[9]' at the end it doesnt work:
$(data).find('.blah')[9].html();
我离开了[9],它只获得了第一个类名为'blah'的项目',我希望它得到第10项。
It I leave the [9] out, it only gets the first item whose class name is 'blah', and I want it to get the 10th item.
推荐答案
相当于
document.getElementsByClassName('blah')[9].innerHTML = 'blah';
is to use the :eq
pseudo-selector:
$(".blah:eq(9)").html('blah');
或 eq
功能:
$(".blah").eq(9).html('blah');
(...然后 html
功能设置内部HTML。)
(...and then the html
function to set the inner HTML.)
这篇关于getElementsByClassName与jquery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文