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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:54:31+00:00 2026-05-23T20:54:31+00:00

I need to change only the first value of a title. I did something

  • 0

I need to change only the first value of a title. I did something but I don’t know if it’s the best way to do it.

HTML:

<div title="Title that have to be change"> the div is here </div>

JS:

$("div").click(function(){
     var title =  $(this).attr('title').split(' ')[0]; 
       /*
           title is now getting the first value (Title), so, 
           i need to change only him.
       */

       // this is the better way to do this ?
       if(title == "Title"){
             $(this).attr("title", "Changed that have to be change");
       }
});

Can I change just a part of the title, instead to do all that?

  • 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-23T20:54:33+00:00Added an answer on May 23, 2026 at 8:54 pm

    Keep all of the parts of the title around. Only change the first part, then join the parts back together to form the new title.

    $("div").click(function(){
         var parts =  $(this).attr('title').split(' '); 
           /*
               now only change part[0]
           */
    
           // now put the parts back together
           $(this).attr("title", parts.join(" " ));
    });
    

    Alternatively, if the transformation is relatively simple (say remove the first word if it’s Title), you could use a regular expression.

    $("div").click(function(){
         var newTitle =  $(this).attr('title').replace(/^Title /,''); // space is important
         $(this).attr("title", newTitle);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some images that need to change, based not only on hover, but
I have a Latex document where I need to change the margins of only
I need change first image in Galleria fullscreen theme ( link ) after Galleria.run().
I have this situation: $(#button).toggle(function(){ $(#window).animate({top:'0%'},1000); },function(){ $(#window).animate({top:'-100%'},1000); }); but I need change it
I use Pjax with tutorial from http://railscasts.com/episodes/294-playing-with-pjax?view=comments I don't need change url and this
First, I'm sorry for the question title but I can't think of a better
Slightly related to this question , but you don't really need to read that.
In Excel 2003, when I change Series.Interior.ColorIndex to a value I need, it has
I need to know when a ListBox has finished rendering for the first time
I need a script to copy only the changed/modified and new files from my

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.