How to access data-code attribute and redirect to some address on click
Hi, I've this HTML code:
- <ul role="menu" class="dropdown-menu language">
- <li><a title="English" data-code="en" class="link" href="#"><img title="English" alt="English" src="image/flags/gb.png"> English</a></li>
- <li><a title="Español" data-code="es" class="link" href="#"><img title="Español" alt="Español" src="image/flags/es.png"> Español</a></li>
- </ul>
And then I wrote this code:
- $('.language > li').click(function(){
- alert($('.link').attr('data-code'));
- });
When I click in first LI all is good and I get "en" but when I click in second one I get "en" too which is wrong because I should get "es", what is wrong? Also how do I redirect to this URL for example: http://server/en/index.php in others words http://server/[data-code]/index.ph?