Answer the question
In order to leave comments, you need to log in
How to remove the last paragraph on a page?
I want to make a button that deletes the last paragraph on the page,
the button has an event handler: onclick="delLastParagraph();"
.
I'm trying to write a function like this:
function delLastParagraph()
{
var paragraphs = document.querySelectorAll('p');
var lastParagparh=paragraphs.lastChild;
Answer the question
In order to leave comments, you need to log in
Even though you were too lazy to even frame your question: https://api.jquery.com/last/ https://api.jquery.com/last-selector/ https://api.jquery.com/remove/
var nodes = div.querySelectorAll('p');
var first = nodes[0];
var last = nodes[nodes.length- 1];
last.remove();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question