Search code examples
javascripttextanchorinnerhtml

How to pass the achor text innerHtml in javascript


I have an anchor text link that contains information that I need to parse:

<a href="javascript:parselink(this)">
    <div class="calendar">
        <div class='day'>8</div>
        <div class="number">75</div>
    </div>
</a>

  <script>
    function parselink(link){
        alert(link.innerHtml);
    }
  </script>

However, I am not able to get the anchor text's innerHhtml.


Solution

  • You have a typo

    innerHtml !== innerHTML
    

    And use onclick, not href to trigger the event

        function parselink(link){ 
            alert(link.innerHTML);
        }
    <a href="#" onclick="parselink(this); return false;">
        <div class="calendar">
            <div class='day'>8</div>
            <div class="number">75</div>
        </div>
    </a>