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: 
**2021 Update:**

MomentJS has been replaced/improved with LuxonJS, a much more up-to-date and newer version. You can find it here: <https://moment.github.io/luxon/#/>

I'll leave the old post for now, since it could sitll help others.

**Old post:**

I'd recommend using the MomentJS libraries. They make all interactions with Dates a lot simpler.

If you use Moment, your code would be as simple as this:

```
var today = moment();
var nextMonth = today.add('month', 1);
// note that both variables `today` and `nextMonth` refer to 
// the next month at this point, because `add` mutates in-place

```

You can find MomentJS here: <http://momentjs.com/>

**UPDATE:**

In JavaScript, the Date.getDate() function returns the current day of the month from 1-31. You are subtracting 6 from this number, and it is currently the 3rd of the month. This brings the value to -3.
Use the [moment.js](https://momentjscom.readthedocs.io/en/latest/) library for time and date management. 

```
import moment = require('moment');

const now = moment();

now.subtract(7, 'seconds'); // 7 seconds ago
now.subtract(7, 'days');    // 7 days and 7 seconds ago
now.subtract(7, 'months');  // 7 months, 7 days and 7 seconds ago
now.subtract(7, 'years');   // 7 years, 7 months, 7 days and 7 seconds ago
// because `now` has been mutated, it no longer represents the current time

```