How to access data-code attribute and redirect to some address on click

How to access data-code attribute and redirect to some address on click

Hi, I've this HTML code:

  1. <ul role="menu" class="dropdown-menu language">
  2.  <li><a title="English" data-code="en" class="link" href="#"><img title="English" alt="English" src="image/flags/gb.png">  English</a></li>
  3.  <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>
  4. </ul>
And then I wrote this code:
  1. $('.language > li').click(function(){
  2.         alert($('.link').attr('data-code'));
  3. });

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?