Reputation: 35761
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();
});
Upvotes: 0
Views: 5464
Reputation: 116987
Just 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); } );
}
Upvotes: 5
Reputation: 24462
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);
});
Upvotes: 1