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

174
Views
How to pick out span tag that doesn't have a class

Using document.getElementsByClassName("span3 pickItem").outerHTML) I set a variable htmlData to contain:

<div itemscope="" class="span3 pickItem">
     <p itemprop="name" class="name">
          <a href="/user/view?id=4943">
               <span>John Doe</span>
               <br />
               <span>'Arizona'</span>
               <br />
               <span>'Student'</span>
          </a>
     </p>
</div>

How can I pick each value from the span tag and console.log them as such:

console.log(...span[0]) output: John Doe

console.log(...span[1]) output: Arizona

console.log(...span[2]) output: Student

about 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Could do something like this

let namesArr = []; 
let name = document.querySelectorAll("span");
name.forEach(function(names) {
   namesArr.push(names.innerHTML);//Stores all names in array so you can access later 
});
console.log(namesArr[0]);
console.log(namesArr[1]);
console.log(namesArr[2]);
about 4 years ago · Santiago Trujillo Report

0

Something like this should work:

// console log all names
const items = document.querySelectorAll('div.pickItem span')
items.forEach(item => {
    console.log(item.innerText)
})

// console each from array index
console.log(items[0].innerText)
console.log(items[1].innerText)
console.log(items[2].innerText)
about 4 years ago · Santiago Trujillo Report

0

let spans = document.getElementsByTagName('span');

console.log(spans[0].innerHTML); //'Joe Doe'
about 4 years ago · Santiago Trujillo 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!