AnswerBun.com

Jquery .last() equivalence to Javascript

Stack Overflow Asked by divja afsa on October 23, 2020

Hi I’m converting Some jquery code to javascript.
what is I’m trying to convert is:

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>");
               });

what have i can manage to convert by googling is

 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>");

I have some problem with converting .last().when i replaced with last with last = frame.contentDocument.querySelector("div").lastChild; or last = frame.contentDocument.querySelector("div").lastElementChild; it shows fFootNote.innerHTML error:Property ‘innerHTML’ does not exist on type ‘ChildNode’ .

if i convert .last() with i replaced with last with last = frame.contentDocument.querySelectorAll("div") it shows no option for replacing .last()

so my question is how can am i going write way?how to convert .last()

One Answer

Hi :) Welcome to stackoverflow !

If you use 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();

Correct answer by giulp on October 23, 2020

Add your own answers!

Related Questions

RGB to hex and hex to RGB

51  Asked on January 3, 2022 by sindar

       

Setup dictionary lazily

8  Asked on January 3, 2022

     

Iterating over directories with Gulp?

5  Asked on January 3, 2022 by nathan-rutman

   

converting a csv file to json + python with specific json format

4  Asked on January 3, 2022 by hattricknz

     

How do you create a gRPC client in .NET Framework?

2  Asked on January 3, 2022 by rich-shipley

     

How do I switch from a merged branch to an new branch?

2  Asked on January 3, 2022 by mohammad-23

   

How can i edit an array in a JSON file from node?

1  Asked on January 3, 2022 by thomas-bouasli

       

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP, SolveDir