getElementsByClassName vs. jquery

前端 未结 8 624
遇见更好的自我
遇见更好的自我 2021-01-04 12:09

If my original function was:

document.getElementsByClassName(\'blah\')[9].innerHTML = \'blah\';

...how would I change that so I get that sa

8条回答
  •  Happy的楠姐
    2021-01-04 12:38

    The equivalent of

    document.getElementsByClassName('blah')[9].innerHTML = 'blah';
    

    is to use the :eq pseudo-selector:

    $(".blah:eq(9)").html('blah');
    

    or the eq function:

    $(".blah").eq(9).html('blah');
    

    (...and then the html function to set the inner HTML.)

提交回复
热议问题