How do I compress this jQuery code?

Hi all,

how do I compress this jquery code? There are a lot of similar items that redundandly repeat themselves.

jQuery("th:contains('Date')").html("Data");
    jQuery("li.previous strong:contains('Previous Match')").html("PARTITA PRECEDENTE");
    jQuery("li.previous strong:contains('Previous player')").html("GIOCATORE PRECEDENTE");
    jQuery("li.previous strong:contains('Previous staff')").html("PRECEDENTE");
    jQuery("li.previous strong:contains('Previous story')").html("NEWS PRECEDENTE");
    jQuery("li.next strong:contains('Next Match')").html("PARTITA SUCCESSIVA");
    jQuery("li.next strong:contains('Next player')").html("GIOCATORE SUCCESSIVO");
    jQuery("li.next strong:contains('Next staff')").html("SUCCESSIVO");
    jQuery("li.next strong:contains('Next story')").html("NEWS SUCCESSIVA");
    jQuery(".sharrre-container span:contains('Share')").html("CONDIVIDI");
    jQuery(".page-title h2:contains('Match Details')").html("INFORMAZIONI");
    jQuery(".page-title h2:contains('Player Profile')").html("PROFILO GIOCATORE");

Open in new window


thanks in advance
badwolfffAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GaryCommented:
Since every line is different then how do you expect to "compress" it?
0
badwolfffAuthor Commented:
could I not create an array or use case or something similar?

Apart for these two lines:
    jQuery("th:contains('Date')").html("Data");
    jQuery(".page-title h2:contains('Match Details')").html("INFORMAZIONI");
which we can ignore here as I pasted them by mistake

all the others can be categorized as:
    jQuery("li.previous strong:contains('Previous Match')").html("PARTITA PRECEDENTE");
    jQuery("li.previous strong:contains('Previous player')").html("GIOCATORE PRECEDENTE");
    jQuery("li.previous strong:contains('Previous staff')").html("PRECEDENTE");
    jQuery("li.previous strong:contains('Previous story')").html("NEWS PRECEDENTE");


    jQuery("li.next strong:contains('Next Match')").html("PARTITA SUCCESSIVA");
    jQuery("li.next strong:contains('Next player')").html("GIOCATORE SUCCESSIVO");
    jQuery("li.next strong:contains('Next staff')").html("SUCCESSIVO");
    jQuery("li.next strong:contains('Next story')").html("NEWS SUCCESSIVA");


    jQuery(".page-title h2:contains('Match Details')").html("INFORMAZIONI");
    jQuery(".page-title h2:contains('Player Profile')").html("PROFILO GIOCATORE");


Perhaps, for example in the first case, create an array (Previous Match, Previous player, Previous staff, Previous story) and match them with another array contains, in the same index positions, (PARTITA PRECEDENTE, GIOCATORE PRECEDENTE, PRECEDENTE, NEWS PRECEDENTE) and then for each li.previous strong:contains could I not match [id of this] from array 1 with the corresponding id in array 2?

I ask this as I have quite a few more sets like this and I don't want to have to keep repeating useless lines.

thanks
0
GaryCommented:
For the sake of a few characters you wouldn't gain anything but for example.

myArray=['Previous Match',"PARTITA PRECEDENTE",'Previous player',"GIOCATORE PRECEDENTE"]

var arrayLength = myArray.length;
for (var i = 0; i < arrayLength; i=i+2) {
    jQuery("li.previous strong:contains('"+myArray[i]+"')").html(myArray[i+1]);
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
badwolfffAuthor Commented:
Thanks, that is great.
Could this be done using jQuery each function?
0
GaryCommented:
A foreach would serve no purpose in this case
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.