Question: Suppose I have a function that returns the starting index (4) of the word 'world' in this HTML string:

```
<div>The world is round</div>

```

This function (outside of my control) works by using jQuery's `.text()` method. However, I need to use jQuery's `.html()` method for what I'm doing.

Using the existing index will give me the letter "n" from the span when using jQuery's `.html()` method. I need to alter this index to take account of additional HTML tags and nested HTML tags that might be in the div e.g.

```
<div><p><span class="highlight">The</span></p> world is round</div>

```

So, this code snippet would return a new index of 42 for the first letter of 'world'. How would I go about doing this? Many thanks!

UPDATE: The code snippet would return the index INCLUDING the tags. I'm not looking to strip the tags. Thanks!

Answer: 
This is a pure-function which takes a passed-in starting date, building on Phil's answer:

```
function deltaDate(input, days, months, years) {
    return new Date(
      input.getFullYear() + years, 
      input.getMonth() + months, 
      Math.min(
        input.getDate() + days,
        new Date(input.getFullYear() + years, input.getMonth() + months + 1, 0).getDate()
      )
    );
}

```

e.g. writes the date one month ago to the console log:

```
console.log(deltaDate(new Date(), 0, -1, 0));

```

e.g. subtracts a month from March 30, 2020:

```
console.log(deltaDate(new Date(2020, 2, 30), 0, -1, 0)); // Feb 29, 2020

```

Note that this works even if you go past the end of the month or year.

**Update:** As the example above shows, this has been updated to handle variances in the number of days in a month.
The oneliner to get for instance the date of yesterday would be:

```
const yesterday = ((date) => date.setDate(date.getDate() - 1) && date)(new Date());

```

It will define an arrow function which receives the `new Date()` as a parameter (date). The reason to make an arrow function is that the new Date object will be used multiple times. First to retrieve the current days (getDate), then to set the days (setDate) and also to return it as a result. So it will return the mutated date, not the original date.

Now this arrow function is defined and will be called immediately with the `new Date()` in order to return the date of yesterday.