Link to home
Start Free TrialLog in
Avatar of badwolfff
badwolfffFlag for United Kingdom of Great Britain and Northern Ireland

asked on

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
Avatar of Gary
Gary
Flag of Ireland image

Since every line is different then how do you expect to "compress" it?
Avatar of badwolfff

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of Gary
Gary
Flag of Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks, that is great.
Could this be done using jQuery each function?
A foreach would serve no purpose in this case