Panos
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');ret urn false;" href="Myurl....">EN</a>
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
window.location.href = targetUrl;
};
<a onclick="setlang('EN');ret
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
check this page : http://jsfiddle.net/3Xwkc/
ASKER
Thank you
regards panos
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
More info here http://www.quirksmode.org/js/this.html
Glad to know it helped.
Thanks for the points and grade.
kiranvj
Thanks for the points and grade.
kiranvj
ASKER
Hi leakim971
I did not see your post to split the points but i think that is the same with kiranvj's solution
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!
ASKER
It is working perfect
Thank you