Redirect without loop

Viewed 37

I have a dropdown menu that grabs the href of another dropdown and saves it to a variable. How can I redirect the page using window.location.replace() with out it looping.

let deutsch_link = '';
$('.lang_list_class li a').each(function() {
  if ($(this).text() == "Deutsch" || $(this).text() == "Deutsche" || $(this).attr("data-language") == "de") {
    deutsch_link = $(this).attr("href");
    console.log(deutsch_link);
    
    window.location.replace(deutsch_link);
         
  }
});
1 Answers

The windows.location.replace is executing the redirection in there. you could try

$(this).attr("href", deutsch_link) 

so the redirection happens when the a tag is actually clicked. If not, let me know a little bit more about the requirement, maybe I am understanding it the wrong way.

Related