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 6120831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:42:48+00:00 2026-05-23T15:42:48+00:00

So basically I have Jack Shephard under ‘div.actor-name a’ & I want that same

  • 0

So basically I have “Jack Shephard” under ‘div.actor-name a’ & I want that same value to be the title attribute for ‘div.actor-image a’. Same thing for “John Lock” as well, so multiple cases.

JQuery:

<script type="text/javascript">
$().ready(function() {
var actortitle = $("div.actor-image a").closest.('div.actor-name a').html();

$("div.actor-image a").each(function() {
$(this).attr('title', actortitle );
});
});
</script>

HTML:

<div id="actor1" class="lost">

<div class="actor-name">
<a href="http://www.lost.com">
Jack Shephard
</a>
</div>

<div class="actor-roles">
ROLES GO HERE
</div>

<div class="actor-image">
<a title="Jack Shephard" id="actor1-image" src="jack.jpg" href="http://www.lost.com"></a>
</div>

</div>



<div id="actor2" class="lost">

<div class="actor-name">
<a href="http://www.lost.com">
John Lock
</a>
</div>

<div class="actor-roles">
ROLES GO HERE
</div>

<div class="actor-image">
<a title="John Lock" id="actor2-image" src="john.jpg" href="http://www.lost.com"></a>
</div>

</div>

The current jQuery isn’t working as expected and is driving me crazy!

  • 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-23T15:42:49+00:00Added an answer on May 23, 2026 at 3:42 pm
    $("div.actor-image a").attr('title', function(i,val) {
        var text = $(this).parent().prevAll('.actor-name').text();
        return $.trim( text );
    });
    

    This uses the attr()[docs] method, but passes it a function. The return value of the function will be the new value.

    In the function, it uses the parent()[docs] method to traverse to the parent of the <a>, then the prevAll()[docs] method to get the .actor-name element, then the text()[docs] method to grab its text content.

    Before it returns the text, it uses the jQuery.trim()[docs] method to trim any leading or trailing whitespace from the text.

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

Sidebar

Related Questions

I basically have a div on my site that always has the same stuff.
I have 2 Databases that basically have the same structure, but different data. (The
I basically have 7 select statements that I need to have the results output
basically have two questions. 1. Is there a c++ library that would do full
I basically have the same problem in this questions: Flash Video still playing in
I basically have a lot of poorly designed code to do something that, I'm
I basically have the same question as bder on the actionscript.org forums , namely
I basically have the exact same problem as here: http://stackoverflow.com/questions/2416155/issue-in-executing-spring-web-project-in-eclipse-on-tomcat-server but the fix for
I basically have a table with headers that I read in from a DB
I basically have a form inside of Flash that I need to submit to

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.