badwolfff
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.
thanks in advance
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");
thanks in advance
Since every line is different then how do you expect to "compress" it?
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("INFORMAZ IONI");
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("INFORMAZ IONI");
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
Apart for these two lines:
jQuery("th:contains('Date'
jQuery(".page-title h2:contains('Match Details')").html("INFORMAZ
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
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
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("INFORMAZ
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks, that is great.
Could this be done using jQuery each function?
Could this be done using jQuery each function?
A foreach would serve no purpose in this case