That is one way but you can do it with Wayfinder.
You can use the following parameters in your TPL
[+wf.subitemcount+]
OR
[+wf.docid+]
OR my favorite
[[Wayfinder? &startId=`0` &level=`1` &rowTpl=`mainMenuRowTpl` &titleOfLinks=`alias`]]
+
<li [+wf.classes+]>
<a href="[+wf.link+]" [+wf.attributes+] title="[+wf.linktext+]" id="[+wf.title+]"></a>
[+wf.wrapper+]
</li>
The trick is to use titleOfLinks and set the title to use the alias field. I personally set up modx to create the alias automatically. If you don’t do it like this you would have to enter the alias yourself. Because the alias is an unique field(almost all the time) you can use it as an ID.
There are other ways to do it
1: Latest wayfinder + phx + custom phx modifier
2. Javascript: Get the name of the link replace special characters with - or _ and insert the id in the DOM