How to get element by class name

前端 未结 4 1186
余生分开走
余生分开走 2020-12-03 17:45

I want to know if there is a way to getElementByClassName(\"classname\").innerHTML function or something to the equivalent of getElementById(\"ClassName\"

4条回答
  •  囚心锁ツ
    2020-12-03 18:33

    If tou use jQuery you can get it as you would in a CSS selector so:

    
    

    then...

    $('.classname').each(function() {
        // get html
        $(this).html();
        // set html
        $(this).html('something');
    });
    

    Notice you have also convenient way to manage innerHTML.

提交回复
热议问题