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

  • Home
  • SEARCH
  • 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 8068275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:36:55+00:00 2026-06-05T12:36:55+00:00

I have this: $(‘li’).click(function() { var currentSrc = $(‘img’, this).attr(‘src’).toString(); var grabAlt = $(‘img’,

  • 0

I have this:

$('li').click(function() { 
    var currentSrc = $('img', this).attr('src').toString();
    var grabAlt = $('img', this).attr('alt').split('|');
    //alert(grabAlt[0]);
    $('.imgSample img').attr('src', currentSrc);
    $('.projectDescription').html('<p class="projectDescription">' + grabAlt[0].join('</p>')); 
    $('.projectTitle').html(grabAlt[1]); 
});

When I remove the [0] and [1] I can alert either and what I’m thinking is the first value [0], does replace the project description, but trying to place each in the respective place doesn’t work at all.

snippet of relevant html:

<section class="workArea">
    <div class="imgSample"><img src="images/samples/testImage2.png" alt="This first part will be a short description. | this second part will be the title."></div>
    <p class="projectDescription">This is to be replaced when an image is clicked on.</p>
    <h3 class="projectTitle">To be replaced</h3>
</section>
</div>

<nav>
    <ul class="print">
        <li class="liRounded"><img width="50" height="50" src="images/samples/image1.png" alt="Should replace the content in the paragraph. | Replace title copy."></li>

        <li class="liRounded"><img width="50" height="50" src="images/samples/image2.png" alt="Second. | Replace title 2."></li>

        <li class="liRounded"><img width="50" height="50" src="images/samples/image3.png" alt="third. | Replace title 3."></li>
    </ul>
</nav>

Is it my syntax or usage that is wrong here?

  • 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-06-05T12:36:57+00:00Added an answer on June 5, 2026 at 12:36 pm

    You were nearly there, but not quite:

    $('li').click(function() { 
    
        var img = $('img', this).get(0);
        var src = img.src;  // no need for .attr
        var alt = img.alt;  //     ditto
    
        var grabAlt = alt.split('|');
    
        $('.imgSample img').attr('src', currentSrc);
        $('.projectDescription').text(grabAlt[0]);
        $('.projectTitle').text(grabAlt[1]); 
    });
    

    Mostly, you don’t need to put a new <p> inside the .projectDescription element, you just needed to change its text contents.

    As @gdoron alluded to, .join() doesn’t do what you appear to think it does – it takes an array of strings, and joins them together with the given separator. It doesn’t concatenate grabAlt[0] with </p>.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this list: <ul class=pagination> <li class=dl-nav-1 current><a href=#>Spring Training 2001</a><span class=visible><img src=img/indicator.png
I have this jQuery code: var thumb = $($('#slider').children('.ui-slider-handle')); setLabelPosition(); $('#slider').bind('slide', function (event, ui)
I have this function // add history paths and save data function AddPath( strTag,
I have this class class Validator implements iValidation{ protected $_fields, $_errors; public function __construct($fields){
Have this in a c# .net application: string key = e.KeyCode.ToString(); in .net 1.1
Have this code: var gradient = ctx.createLinearGradient(0,0, 20, 0); gradient.addColorStop(0.8, rgb(250,250,0)); gradient.addColorStop(1, rgb(150,150,0)); ctx.fillStyle
I have this function: public static string Join(this IEnumerable<string> strings, string separator) { return
I have this function in my custom dynamic array class that allows the user
I have this function Public Function parseEmployee(ByVal employeeId As Integer, _ ByVal ws As
Have this query: SELECT HOUR( DATE ) AS hr, COUNT( * ) AS cnt

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.