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

79
Views
how to map only parts of images source attribute

$('button').on('click', function(){
var str = $.map($('.bimg'), (e) => $(e).attr('src')).join(',');
console.log(str);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<img class='bimg' src='gall/lorem.jpg' alt='img'>
<img class='bimg' src='gall/ipsum.jpg' alt='img'>
<img class='bimg' src='gall/dolor.jpg' alt='img'>
<button>CLICK</button>

Result:

gall/lorem.jpg,gall/ipsum.jpg,gall/dolor.jpg

What I need:

lorem,ipsum,dolor
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Add the following to your map

.split('/').pop().split('.').shift()

So we split on each / and use pop() to get the last one found

Then we'll split on each . and use shift() to get the first part

$('button').on('click', function(){
    var str = $.map($('.bimg'), (e) => $(e).attr('src').split('/').pop().split('.').shift()).join(',');
    console.log(str);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<img class='bimg' src='gall/lorem.jpg' alt='img'>
<img class='bimg' src='gall/ipsum.jpg' alt='img'>
<img class='bimg' src='gall/dolor.jpg' alt='img'>
<button>CLICK</button>

lorem.jpg,ipsum.jpg,dolor.jpg

about 4 years ago · Juan Pablo Isaza Report

0

You can use regex to get the image name from src.

$('button').on('click', function() {
  var str = $.map($('.bimg'), (e) => $(e).attr('src').match(/\/(.*)\.jpg/)[1]).join(',')
  console.log(str);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<img class='bimg' src='gall/lorem.jpg' alt='img'>
<img class='bimg' src='gall/ipsum.jpg' alt='img'>
<img class='bimg' src='gall/dolor.jpg' alt='img'>
<button>CLICK</button>

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!