On my site I want to have a language selection dropdown (EN English, NL Dutch, FR French). It looks like this:
All the animations etc are OK, but I’d like the text in the dropdown trigger to reflect the current selection… So if someone selects “FR” for French, the trigger should change to FR. Is there an option I overlooked or do I need to do it via Javascript?
More modular/DRY is to create ifrelated to url slug (If url contain fr select fr).
if (window.location.href.indexOf("/fr/") > -1) {
// block of code to be executed if condition1 is true
$(".dropdown select").val("fr");
} else if (window.location.href.indexOf("/en/") > -1) {
// block of code to be executed if the condition1 is false and condition2 is true
$(".dropdown select").val("en");
}
Thanks @Siton_Systems, that will do nicely. I thought that indeed JS was needed for the job. Your solution is very elegant however, I was going to fiddle with the dropdown itself
Sorry I didn’t share the site as it should, I just realised I should have done that differently. But I’m OK now.