Web Analytics Made Easy -
StatCounter How to access tag text with no IDs - CodingForum

Announcement

Collapse
No announcement yet.

How to access tag text with no IDs

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to access tag text with no IDs

    My website (Joomla-based) is producing the following code:

    <li class="jcalpro_events_event">
    ....
    <span class="jcalpro_events_category">
    <a href="/bookings/my-schedule/99-contra">Contra</a>
    </span>
    ....
    </li>

    I am trying to access the text between the <a> ..</a> tags. The closest I have got is to use

    Code:
     var c = document.getElementsByClassName("myclass");
    using console.log I can see that it returns values in the following format

    <span class="myclass">
    <a href="/bookings/my-schedule/99-contra">Contra</a>
    </span>

    Any help in targeting the text between the tags would be much appreciated.

  • #2
    Try this:
    Code:
    var txt = document.querySelector("li.jcalpro_events_event span.jcalpro_events_category a").innerHTML;

    Comment


    • #3
      Thank you

      Many thanks.

      I have solved the problem using

      Code:
      var category = document.getElementsByClassName("jcalpro_events_category")[i].textContent;
      However, your answer gave me important clues to solving the next part of my coding!

      Comment

      Working...
      X