JavaScript How do I find the last descendent of a div?

I want to find last descendent div of the html below. I tried but it finds the first occurrence of the div.

How can I achieve this?

HTML:

<div class='greatparent'>
  <div>
    <div>
      <div>
        <div>
          <div>
            find this div element
          </div>
        </div>
      </div>
    </div>
  </div>
</div>

jQuery:

$('.greatparent').find('div:last-child').html('you found me');
Answer:1

You can solve this using jQuery by finding the only <div> element that doesn't have a <div> child:

$(".greatparent").find("div:not(:has(div))")
Answer:2

I am trying to take what a user enters in a textbox, and then write that input to a paragraph on the page, and stop the page refreshing so that they can then copy that input for use elsewhere. (it'...

I am trying to take what a user enters in a textbox, and then write that input to a paragraph on the page, and stop the page refreshing so that they can then copy that input for use elsewhere. (it'...

  1. html javascript display none
  2. html javascript display text
  3. html javascript display
  4. html javascript display all images in a folder
  5. html javascript display image
  6. html javascript display variable
  7. html javascript display date and time
  8. html javascript display block
  9. html javascript display json
  10. html javascript display running time
  11. html javascript display pdf
  12. html javascript display message
  13. html javascript display current time
  14. html javascript display current date
  15. html javascript display date
  16. html javascript display array
  17. html display javascript object
  18. html display javascript function output
  19. html display javascript variable value
  20. html display javascript return value

By using JavaScript or jQuery, I am trying to figure out if a word, say "casablanca", is available on the page? The page I am working on makes an ajax call which changes the content of the page. So I ...

By using JavaScript or jQuery, I am trying to figure out if a word, say "casablanca", is available on the page? The page I am working on makes an ajax call which changes the content of the page. So I ...

  1. searching word on web page

This my code when click the button i want to display button dynamic id to the specific place by calling that id: this is my code: <span id="2" class="view-details">View Details</span> $( ...

This my code when click the button i want to display button dynamic id to the specific place by calling that id: this is my code: <span id="2" class="view-details">View Details</span> $( ...

  1. jquery append not working with html

I have a simple jQuery slider but cant get multiple instances of it to work on the page, I am sure its an easy fix but my brain is just not co-operating atm function testSlide() { var testAnim = ...

I have a simple jQuery slider but cant get multiple instances of it to work on the page, I am sure its an easy fix but my brain is just not co-operating atm function testSlide() { var testAnim = ...

  1. simple jquery slider free download
  2. simple jquery slider codepen
  3. simple jquery slider plugin
  4. simple jquery slider example with source code
  5. simple jquery slider with next previous buttons
  6. simple jquery slider
  7. simple jquery slider w3schools
  8. simple jquery slider code
  9. simple jquery slider jsfiddle
  10. simple jquery slider tutorial
  11. simple jquery slider with dot navigation
  12. simple jquery slider responsive
  13. simple jquery slider example
  14. simple jquery slider autoplay
  15. simple jquery slider with thumbnails
  16. simple jquery slider with bullets
  17. simple jquery slider download
  18. simple jquery slider code example
  19. simple jquery slider with controls
  20. simple jquery slider left to right