Is there an way to delete everything after a particular div with javascript/jquery and replace with new code?
The DIV’s are generated dynamically and I want to be able to delete everything after
the last div which looks something like:
<div class="galImage"> **div content** </div>
/**delete everything after this point and replace with code below**/
</div>
</body>
</html>
I’ve tried $('.galImage').nextAll().remove(); which I found else where on stackoverflow but it doesn’t seem to have any effect – is nextAll() even a legitimate function?
Your question is a little unclear because you’ve posted what appears to be a fragment of markup.
From what I can tell, you want to remove a
textNode. Selectors and most jQuery traversal methods can’t find text nodes, but you can select it using the native API.If there are additional nodes to remove, then you can use a loop:
Considering that you’re using jQuery, if there are indeed actual elements (not just text nodes) to remove, you should use
.remove(), otherwise jQuery’s cache won’t be updated, which could cause a memory leak.Or if you want a full jQuery solution, you could do this: