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

122
Views
Get first row with jQuery on a specific HTML tag

This is my HTML:

<p class="myclass">

<span class="generalclass">text1</span>
<span>text2</span>
<span>text3</span>
</p>

<p class="myclass">

<span class="generalclass">text1</span>
<span>text2</span>
<span>text3</span>
</p>

and each of the other 3 <p> tags are identical.

This my jQuery Code:

var promo = $('[class^="myclass"]').map(function() {
    return $(this).text();
    //I try something like return $(this).children.text(':first') but NOT Work
}).get();
let promo1 = promo[0];
let promo2 = promo[1];
let promo3 = promo[2];

Results: promo1 = text1 text2 text3

How can I get the text from only <span> / ROW 1 and not the other span tag content?

tks

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

var promo = $('[class^="myclass"]').map(function() {
    return $(this).children(":first").html();
}).get();
let promo1 = promo[0];
let promo2 = promo[1];
let promo3 = promo[2];
about 4 years ago · Juan Pablo Isaza Report

0

try this code to get the value from the first <span>

var promo = $('[class^="myclass"]').map(function() {
    return $(this).find("span:first-of-type").text();
}).get();
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!