Jonathan Eckman
Jonathan Eckman

Reputation: 2077

SharePoint javascript: find all <a> in a div

I am trying to find all the tags in a div and compare the href to the page in the current url. If they are the same I will add css to the parent of the tag. Why wont this work to find the tags? This is being used in SharePoint.

<script>
  var jse_vertical_nav = document.getElementById('JSE_vertical_nav');
  alert(jse_vertical_nav.getElementsByTagName('a').length);
</script> 

<div id="JSE_vertical_nav">
  <div class="jse_link_row">
    <a href="../SitePages/Home.aspx">HOME</a>
  </div>
  <div class="jse_link_row">
    <a href="#">ABOUT</a>
  </div>
  <div class="jse_link_row">
     <a href="#">NEWS</a>
  </div>
</div>

Upvotes: 0

Views: 171

Answers (1)

Amberlamps
Amberlamps

Reputation: 40488

It does not work, because you need to use JavaScript AFTER you output your HTML!

Upvotes: 6

Related Questions