Jquery .last() 等价于 Javascript

Jquery .last() equivalence to Javascript

您好,我正在将一些 jquery 代码转换为 javascript。 我要转换的是:

frame.contents().find("div[class='footNote']").remove();
               var last = frame.contents().find("div").last();

               _.each($scope.currencyNotes, function (item) {
                   var footNote = $("<div class='footNote' />");
                   footNote.css('font-size', '13px');
                   

                   var fFootNote =footNote.appendTo(last);
                   fFootNote.html("<div style='float:left;width:25px'>" + item.Id + "</div>" + " <div style='float:left;width:80%'>" + item.Text + "</div>");
               });

我可以通过谷歌搜索设法转换的是

 frame.contentDocument.querySelector("div[class='footNote']").parentNode.removeChild(frame);
      var last = frame.contentDocument.querySelector("div").last();

      Array.from(this.currenyNotes).forEach((item:any) => {
        //todo
        var footNote = document.createElement("div class='footNote' ");
        footNote.style.fontSize = "13px";
       
        

        var fFootNote = footNote.appendChild(last);
        fFootNote.innerHTML("<div style='float:left;width:25px'>" + item.Id + "</div>" + " <div style='float:left;width:80%'>" + item.Text + "</div>");

我在转换 .last() 时遇到了一些问题。当我将 last 替换为 last = frame.contentDocument.querySelector("div").lastChild;last = frame.contentDocument.querySelector("div").lastElementChild; 时,它显示 fFootNote.innerHTML error:Property 'innerHTML' 在类型 'ChildNode' 上不存在。

如果我将 .last() 转换为 i 替换为最后一个 last = frame.contentDocument.querySelectorAll("div") 它显示没有替换 .last()

的选项

所以我的问题是我该怎么写?如何转换.last()

嗨 :) 欢迎使用 Whosebug!

如果你使用querySelectorAll() the NodeList that it returns can be converted to an Array on which you can call pop()

// something like this

let last = Array.from(document.querySelectorAll('div')).pop();