how to use simple html dom get a div inner text

前端 未结 4 1882
無奈伤痛
無奈伤痛 2020-12-06 23:39
innertext

Jow can I access i

4条回答
  •  半阙折子戏
    2020-12-06 23:56

    If the styles are consistent, then you can loop over all divs in the document and filter them by style.

    var divs = document.getElementsById("div");
    
    for (var i = 0; i < divs.length; i++) {
        var div = divs[i];
    
        // skip the current div if its styles are wrong
        if (div.style.cssFloat !== "left"
         || div.style.marginTop !== "10px"
         || div.style.fontFamily !== "Verdana"
         || div.style.fontSize !== "13px"
         || div.style.color !== "#404040") continue;
    
        var text = div.innerText || div.textContent;
    
        // do something with text
    }
    

提交回复
热议问题