Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

193
Views
Get html attribute value

How to get the span value through javascript. I got the below through

document.getElementsByClassName("breadcrumb-item")[1]

I want to get the span value. How to get it using javascript.

<li class="breadcrumb-item">
       <a href="@crumbUrl">
         <span>
           @Html.Raw(breadcrumb.Name)
         </span>
       </a>
    </li>
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You can use querySelector like:

console.log(document.querySelector('.breadcrumb-item > a > span').innerHTML);
<ul>
  <li class="breadcrumb-item">
    <a href="@crumbUrl">
      <span>
        value   <!--@Html.Raw(breadcrumb.Name)-->
      </span>
    </a>
  </li>
</ul>

Reference:

  • Document.querySelector()

If is more than 1

document.querySelectorAll('.breadcrumb-item > a > span').forEach(el =>{
  console.log(el.innerHTML);
});
<ul>
  <li class="breadcrumb-item">
    <a href="@crumbUrl">
      <span>
        value   <!--@Html.Raw(breadcrumb.Name)-->
      </span>
    </a>
  </li>
   <li class="breadcrumb-item">
    <a href="@crumbUrl">
      <span>
        value2   <!--@Html.Raw(breadcrumb.Name)-->
      </span>
    </a>
  </li>
</ul>

Reference:

  • Document.querySelectorAll()
  • Array.prototype.forEach()
about 4 years ago · Juan Pablo Isaza Report

0

You can create a variable to get element:

var list = document.getElementsByClassName("breadcrumb-item")[0];

var spanVal = list.getElementsByTagName("span")[0].innerHTML;

console.log(spanVal);

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!