I have a piece of html code that is incorporated into multiple html files, each controlled by different controllers. I need to be able to access elements from this included html using their ids in every controller. Below is the html snippet that is included in each file:
<ul class="nav menu" >
<li id="tom_nav_bar"><a href="/#tom">
<svg class="glyph stroked dashboard-dial">
<use xlink:href="#stroked-dashboard-dial"></use>
</svg>
BEX Dashboard</a></li>
<li id="sonar_nav_bar"><a href="#/sonar">
<svg class="glyph stroked chevron right">
<use xlink:href="#stroked-chevron-right"/>
</svg>
Sonar</a></li>
<li id="teamcity_nav_bar"><a href="/#teamcity">
<svg class="glyph stroked chevron right">
<use xlink:href="#stroked-chevron-right"/>
</svg>
TeamCity</a></li>
<li id="kpi_definitions_nav_bar"><a href="#/kpi_definitions">
<svg class="glyph stroked chevron right">
<use xlink:href="#stroked-chevron-right"/>
</svg>
Kpi Definitions</a></li>
<li id="credit_risk_custom_report_nav_bar"><a href="#/department_custom_report">
<svg class="glyph stroked chevron right">
<use xlink:href="#stroked-chevron-right"/>
</svg>
CREDITRISK Custom Report (beta)</a></li>
</ul>
Let's refer to this code as 'navbar.html'. Now let's take a look at one of the 4 html files where this code is included:
<div ng-include src="'navbar.html'" class="col-sm-3 col-lg-2 sidebar"></div>
Now, in my controllers, I want to target an element with the id 'tom_nav_bar', but unfortunately, I'm unable to do so:
document.getElementById("tom_nav_bar").className = "active";
The issue here is that getElementById is returning null.