I have a function that checks the page for a given string (date) like so:
function findDate(date) {
if ((document.documentElement.innerText).indexOf(date) > -1) {
return this;
} else {
return false;
}
}
My question is, once I find this text, how do I get the parent element so I can later prepend text immediately after the element ends.
For example, if my date is stored in an element like this:
<div id="date">October 6th, 2015</div>
I want to findDate("October 6th, 2015").parentElement.after.prepend("text")
.
HTML should end up being:
<div id="date">October 6th, 2015</div>stuff
How would I go about doing this?