admin管理员组文章数量:1392893
I am trying to pass the clicked event (event.target) to a function inside a function that is being called when clicked how would i do this?
function showGrid(){
updateTag()
}
function updateTag(){
/*how do i get the event.target passed here? */
alert(e.target)
}
$(".gridViewIcon").click(function(e) {
showGrid();
});
I am trying to pass the clicked event (event.target) to a function inside a function that is being called when clicked how would i do this?
function showGrid(){
updateTag()
}
function updateTag(){
/*how do i get the event.target passed here? */
alert(e.target)
}
$(".gridViewIcon").click(function(e) {
showGrid();
});
Share
Improve this question
asked Sep 17, 2009 at 17:50
adardesignadardesign
35.9k15 gold badges66 silver badges86 bronze badges
2 Answers
Reset to default 5Just pass the event argument object down through your function calls.
function showGrid(e){
updateTag(e);
}
function updateTag(e){
/*how do i get the event.target passed here? */
alert(e.target);
}
$(".gridViewIcon").click(function(e) {
showGrid(e);
});
To include the argument into a nested jQuery function, you can create a closure on the variable like so:
function updateTag(e){
alert(e.target);
...
var x = e;
something.each( function(i) { alert(x.target); } );
}
Add e
as a parameter for each function you need to pass it too.
function showGrid(e){
updateTag(e)
}
function updateTag(e){
/*how do i get the event.target passed here? */
alert(e.target)
}
$(".gridViewIcon").click(function(e) {
showGrid(e);
});
本文标签: javascriptpass the etarget to a function thats called when element is clickedStack Overflow
版权声明:本文标题:javascript - pass the e.target to a function thats called when element is clicked - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744789932a2625227.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论