Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 229543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:46:29+00:00 2026-05-11T19:46:29+00:00

Hi i’m trying to use jQuery/javascript to make my life easier. I’m trying to

  • 0

Hi i’m trying to use jQuery/javascript to make my life easier. I’m trying to use it to auto fill in the various html elements with the name of the place and country which comes from the file name of the image. Below is a sample of some of the html i have to work with:

<div class="boxgrid">
<a href="gallery/angkor - cambodia.jpg" title="[PLACE] - [COUNTRY]">
  <img src="gallery/thumbs/angkor - cambodia.jpg" alt="[PLACE] - [COUNTRY]" width="100" height="100"/>
</a>
  <div class="boxcaption">
    <span class="place">[PLACE]</span>
    <span class="country">[COUNTRY]</span>
  </div>
</div>

Imagine this block of html is repeated multiple times for every image in the gallery so i assume .each() will need to be used.

The idea is that [NAME OF PLACE] and [NAME OF COUNTRY] should be filled in with the image’s file name using the – (dash) as the delimiter between the two values. How can I accomplish this with jQuery/javascript? (i realise i should use a server side language or go about this another way but this is what i’m restricted to)

As a bonus the first letter of each of the values should be capitalised, for example Angkor – Cambodia .

Thank you, any help would be much appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T19:46:30+00:00Added an answer on May 11, 2026 at 7:46 pm

    Here’s the full code with trimming and capitalization of the first letter for Place and Country.

    String.prototype.capitalize = function(){
        return this.replace(/\S+/g, function(a){
            return a.charAt(0).toUpperCase() + a.slice(1).toLowerCase();
        });
    };
    
    $(function(){
     $('.boxgrid').each(function(){
        var placeCountry = $(this).find('img').attr('src')
                                .replace('gallery/thumbs/','')
                                .replace('.jpg','').capitalize();
    
        var place = $.trim(placeCountry.split('-')[0]); 
        var country = $.trim(placeCountry.split('-')[1]);
        $(this).find('a').attr('title',placeCountry);
        $(this).find('img').attr('alt',placeCountry);
        $(this).find('.place').html(place);
        $(this).find('.country').html(country);
     });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am reading a book about Javascript and jQuery and using one of the
I am trying to render a haml file in a javascript response like so:
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I used javascript for loading a picture on my website depending on which small

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.