如果我的原始功能是:
document.getElementsByClassName('blah')[9].innerHTML = 'blah';
...我将如何更改它,以便在jquery中得到相同的项目?我有这个,但是当我在末尾加上“[9]”时,它不起作用:
$(data).find('.blah')[9].html();
我将[9]排除在外,它仅获得类名称为'blah'的第一个项目,而我希望它获得第10个项目。
最佳答案
相当于
document.getElementsByClassName('blah')[9].innerHTML = 'blah';
是使用
:eq
pseudo-selector:$(".blah:eq(9)").html('blah');
或
eq
function:$(".blah").eq(9).html('blah');
(...然后是
html
function来设置内部HTML。)关于javascript - getElementsByClassName vs.jQuery,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15719222/