admin管理员组文章数量:1336113
I used document.activeElement.href
for get target location of clicked tag. Its worked property in firefox, but not working in chrome.
I want to get "href"
location of a clicked(active) element in other function outside of it.
like this:
function animate() {
alert(document.activeElement.href); //not working in chrome
});
Thanks alot
EDIT :
Remember i dont want to use "this" or $(this) because it doesn't work in a function outside of the element.
I know i can use onclick="...."
then use "$(this)"
for each element but i dont want this.
My question is simple:
can i get clicked(active) elementID in a function outside of it? (Except in firefox)
I used document.activeElement.href
for get target location of clicked tag. Its worked property in firefox, but not working in chrome.
I want to get "href"
location of a clicked(active) element in other function outside of it.
like this:
function animate() {
alert(document.activeElement.href); //not working in chrome
});
Thanks alot
EDIT :
Remember i dont want to use "this" or $(this) because it doesn't work in a function outside of the element.
I know i can use onclick="...."
then use "$(this)"
for each element but i dont want this.
My question is simple:
Share edited Aug 16, 2013 at 12:39 Nader asked Aug 16, 2013 at 11:01 NaderNader 3764 silver badges13 bronze badges 3can i get clicked(active) elementID in a function outside of it? (Except in firefox)
-
@Liam, your link says
activeElement
is supported by Chrome 2 and later (MDN says the same, the accepted answer saying Chrome 9+ is apparently a mistake). – Frédéric Hamidi Commented Aug 16, 2013 at 11:06 - @FrédéricHamidi, sorry must of misread it. My bad – Liam Commented Aug 16, 2013 at 11:07
-
@Nader, is there any chance you set the focus to another element before calling
animate()
? – Frédéric Hamidi Commented Aug 16, 2013 at 11:07
3 Answers
Reset to default 3Here is a solution using addEventListener
from Vanilla JS
document.addEventListener('click', function (e) {
var elm = e.target;
if (elm && elm.nodeType === 1 && elm.nodeName === 'A') {
alert(elm.href);
}
});
That element would be focused then
$("a:focus").prop("href")
http://jsfiddle/kYJ3n/
you could do this with jQuery
$(document).on('click', 'a', function() {
alert($(this).attr('href'));
});
this does though depend on when you actually call your event. You haven't specified this so it's hard to tell.
本文标签: javascriptdocumentactiveElementhref not working in chromeStack Overflow
版权声明:本文标题:javascript - document.activeElement.href not working in chrome - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742404045a2468455.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论