TransWikia.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!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP