Link to home
Start Free TrialLog in
Avatar of Panos
PanosFlag for Germany

asked on

Jquery attr href problem

hello experts.
I want to use attr href for  window.location.href value but i get 'undefined' in my alert.
Below my code:
var setlang = function (a) {
        $.cookie("MYLANGUAGE", a);
            var targetUrl = $(this).attr("href");alert(targetUrl);
             window.location.href = targetUrl;
    };
<a onclick="setlang('EN');return false;" href="Myurl....">EN</a>
ASKER CERTIFIED SOLUTION
Avatar of Kiran Paul VJ
Kiran Paul VJ
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Panos

ASKER

Hi kiranvj
It is working perfect
Thank you
Avatar of Panos

ASKER

Thank you
regards panos
Earlier it was not working because  this inside a function refers to owner of that function.

More info here http://www.quirksmode.org/js/this.html
Glad to know it helped.

Thanks for the points and grade.

kiranvj
Avatar of Panos

ASKER

Hi leakim971
I did not see your post to split the points but i think that is the same  with kiranvj's solution
Hi @panosms, no worry, kiranvj answered it successfully!