This question already has an answer here:
- Javascript multiple or condition check 4 answers
Goal: Depending on which "or" statement matches the text have a href change to the correct link.
I have a list of 250 jobs that I need to sort through and generate a top 10 list. The top 10 list is already being generated I now need to set the correct href for each job in the top 10. I'd really like to find a better way than doing literally 2,500 if statements checking each job (250 x 10 jobs to check).
My solution is an if statement which checks each rank. This works fine. However how do I determine which "rank" matched?
The $(this).attr
section needs to change the correct rank's href. For example if rank4 matched entrepreneur I'd need rank4's href to change not the others. I tried to use 'this' with no luck.
Any advice? Thanks for the help!
What the variables look like: var rank2 = $('#jobRank2').html()
if(rank1 || rank2 || rank3 || rank4 || rank5 || rank6 || rank7 || rank8
|| rank9 || rank10 == "Entrepreneur"){
$(this).attr("href", "/entrepreneur")
}
Aucun commentaire:
Enregistrer un commentaire