I use msDropDown
to convert the <select>
to <ul>
list for languages switcher. But the problem is that with this jQuery plugin, the select takes a long time to load after page loaded.
So, how can I use a ul
list rather than select
?
This is my select code:
<select name="lang" class="language" onchange="location.href='index.php?lang='+this.value+''.$trackpage.'">
<option name="lang" data-image="style/lang/de.png" value="de">Deutsch</option>
<option name="lang" data-image="style/lang/en.png" value="en" selected="selected">English</option>
<option name="lang" data-image="style/lang/es.png" value="es">Espanol</option>
<option name="lang" data-image="style/lang/fr.png" value="fr">Francais</option>
<option name="lang" data-image="style/lang/it.png" value="it">Italiano</option>
</select>
I tried with:
<ul onchange="location.href='index.php?lang='+this.value+'">
<li>
<a href="" name="lang" data-image="style/lang/de.png" value="de">English</a>
</li>
</ul>
but value
and onchange
is not supported by ul
and a
.
Is there a way to make ul
works with the select
attributes?
Thank you! And sorry for my bad English!
Updated Answer 2015
As this question is still visited very often and due to some requests in the comments, I've revisit my code. You can still find my original answer below.
HTML
JavaScript
CSS
Demo
Try before buy
Original Answer From 2013
I would do it like this:
This one adds a class the the selected element. This works, if you stay on that very page after the select and don't use
location.href
.You can't use the select attributes, instead you can create your own attributes and use them in
<ul>
elementMaybe this will help you
First the html code
Next the jquery code
i have did it without the plugin.
Pay attention that i created a
data-val
attribute so store the desire language. and i getting this attribute using jquery codeA very simple one (ul to select dropdown jquery transformation) no need to change html, very useful for mobile menus: