JavaScript | Grab inner HTML Text
<p>Let's say I have this line somewhere in my code:</p>

<pre><code>&lt;ul id="mobileBtnsBot"&gt;
            &lt;li&gt;
                &lt;a href="/m/alert/index.shtml"&gt;&lt;span class="alertsBtn"&gt;&lt;/span&gt;&lt;span class="btnText"&gt;Alerts &amp; Advisories&lt;/span&gt;&lt;/a&gt;&lt;div class="button_last"&gt;&lt;/div&gt;
            &lt;/li&gt;
            &lt;li&gt;
                &lt;a href="/m/alert/index.shtml"&gt;&lt;span class="schedBtn"&gt;&lt;/span&gt;&lt;span class="btnText"&gt;Schedules&lt;/span&gt;&lt;/a&gt;&lt;div class="button_last"&gt;&lt;/div&gt;
            &lt;/li&gt;
            &lt;li&gt;
                &lt;a href="/m/alert/index.shtml"&gt;&lt;span class="mapsBtn"&gt;&lt;/span&gt;&lt;span class="btnText"&gt;Maps &amp; Stations&lt;/span&gt;&lt;/a&gt;&lt;div class="button_last"&gt;&lt;/div&gt;
            &lt;/li&gt;
            &lt;li&gt;
                &lt;a href="/m/alert/index.shtml"&gt;&lt;span class="trainBtn"&gt;&lt;/span&gt;&lt;span class="btnText"&gt;TrainView&lt;/span&gt;&lt;/a&gt;&lt;div class="button_last"&gt;&lt;/div&gt;
            &lt;/li&gt;
            &lt;li&gt;
                &lt;a href="/m/alert/index.shtml"&gt;&lt;span class="ntaBtn"&gt;&lt;/span&gt;&lt;span class="btnText"&gt;Next To Arrive&lt;/span&gt;&lt;/a&gt;&lt;div class="button_last"&gt;&lt;/div&gt;
            &lt;/li&gt;
            &lt;li&gt;
                &lt;a href="/m/alert/index.shtml"&gt;&lt;span class="faresBtn"&gt;&lt;/span&gt;&lt;span class="btnText"&gt;Fares&lt;/span&gt;&lt;/a&gt;&lt;div class="button_last"&gt;&lt;/div&gt;
            &lt;/li&gt;
            &lt;li&gt;
                &lt;a href="/m/alert/index.shtml"&gt;&lt;span class="mediaBtn"&gt;&lt;/span&gt;&lt;span class="btnText"&gt;@ SEPTA&lt;/span&gt;&lt;/a&gt;&lt;div class="button_last"&gt;&lt;/div&gt;
            &lt;/li&gt;
            &lt;li&gt;
                &lt;a href="/m/alert/index.shtml"&gt;&lt;span class="button_beg"&gt;&lt;/span&gt;&lt;span class="btnText"&gt;Find my Location&lt;/span&gt;&lt;/a&gt;&lt;div class="button_last"&gt;&lt;/div&gt;
            &lt;/li&gt;
        &lt;/ul&gt;
</code></pre>

<p>I want to use JavaScript to find the <code>&lt;a&gt;</code> holding the text <code>Find my location</code> and hide it according to whichever user-agent your on.</p>

<p>I know you are not supposed to use user-agents as such but I can't use any server-side languages. </p>

<p>If anyone knows how to accomplish this or has a better idea, please share.</p>

<p>EDIT: This page is being created from a web form in Alfresco CMS. If I give it an ID they all get the ID.</p>

<p>isBrowser.js</p>

<pre><code>if (navigator.userAgent.indexOf('Gecko')!= -1
         || navigator.userAgent.indexOf('MSIE')!= -1 || navigator.userAgent.indexOf('Opera')!= -1 || navigator.userAgent.indexOf('Chrome')!= -1) {
    document.write('&lt;link rel="stylesheet" href="/m/css/smartmobile.css" type="text/css" /&gt;');
}
else if (navigator.userAgent.indexOf('webkit')!= -1) {
    document.write('&lt;link rel="stylesheet" href="/m/css/smartmobile.css" type="text/css" /&gt;');
}
else{
  alert("load mobile css");
  document.write('&lt;link rel="stylesheet" href="/m/css/mobile.css" type="text/css" /&gt;');
    function hideListItem(text)
    {
        var ul = document.getElementById("mobileBtnsBot");
        alert("line1");
        for(var i = 0; i &lt; ul.childNodes.length; i++)
        {
          alert("line2-loop");
            var li = ul.childNodes[i];
    alert("line3-loop");
            // Element node.
            if (li.nodeType == 1)
            {
              alert("line4-loop");
                // Find the text in all of the inner-html.
                if (li.innerHTML.indexOf(text) != -1)
                {
                  alert("line5-loop");
                    li.style.display = "none";
                    break;
                }
                alert("line6-loop");
            }
            alert("line7-loop");
        }
        alert("line8");
    }
     hideListItem("Find my Location");
}
</code></pre>

<p>mobile-script.js</p>

<pre><code>window.onload = function () {
setTimeout(function(){window.scrollTo(0, 1);}, 100);
var linkElementLnk = document.getElementById("BackButtonlnk");
linkElementLnk.style.display = 'none';
insert();
}

function insert(){
var linkElement = document.getElementById("BackButton");
var linkElementLnk = document.getElementById("BackButtonlnk");
var loc_array = document.location.href.split('/');

if (loc_array[loc_array.length-3] == "maps"|| loc_array[loc_array.length-2] == "stations" || loc_array[loc_array.length-3] == "stations" )
{
  linkElementLnk.style.display = 'block';
  var newT = document.createTextNode("Stations &amp; Maps");
}
else if (loc_array[loc_array.length-3] == "m")
{
  linkElementLnk.style.display = 'none';
}
else if (loc_array[loc_array.length-3] != "m")
{
    linkElementLnk.style.display = 'block';

     if (loc_array[loc_array.length-2] == "w" || loc_array[loc_array.length-2] == "s" || loc_array[loc_array.length-2] == "h" )
     {
        var newT = document.createTextNode(unescape(capWords(loc_array[loc_array.length-2])));
     }

     else
     {
          if (loc_array[loc_array.length-1] == "index.html" || loc_array[loc_array.length-1] == "index.shtml" || loc_array[loc_array.length-1] == "")
          {
          var newT = document.createTextNode(unescape(capWords(loc_array[loc_array.length-3])));
          }
          else
          {
          var newT = document.createTextNode(unescape(capWords(loc_array[loc_array.length-2])));
          }
     }
}
linkElement.appendChild(newT);
}
function capWords(str){ 
   var words = str.split(" "); 
   for (var i=0 ; i &lt; words.length ; i++){ 
      var testwd = words[i]; 
      var firLet = testwd.substr(0,1); 
      var rest = testwd.substr(1, testwd.length -1) 
      words[i] = firLet.toUpperCase() + rest 
   }
   return words;
} 
</code></pre>
