How to get html tag ids from template?

WordPress doesn’t operate with DOM for the purpose of page source generation from templates. Templates are treated and run as PHP source files, producing any and all output.

Unless you have control over actual templates your options likely are:

  1. Attempting to buffer and rewrite output (rather fragile, more so for publicly released plugin)
  2. Adjust markup with JavaScript client–side on already generated page source