Search code examples
javascripthtmlgoogle-tag-manager

How to extract the <title> value


JS is not my main skill, hope someone can help. I am trying to make a GTM variable to extract . Problem is that I cant use class="rg-trailer-icon" as a class name because it changes based on the truck type that is viewed (trailer, truck, etc)

enter image description here

Thank you!


Solution

  • You can extract the title. You just have to scramble through.

    t = document.querySelector('#scheduleContainer svg title').innerHTML
    console.log(t)
    <div id="scheduleContainer">
      <div>
        <div>
          <svg>
            <title>Hello</title>
            <path>
              </svg>
          </div>
        </div>
    </div>