function works in document.ready but not as a normal function
Goodmorning,
i have made een function and it works on document.ready, but it doesnt work when i put it out of document.ready....:/
here is the code:
- //event openen
var klikevent = function() {
var imgid = $(this).find("img");
var id = $(this).attr("data-id");
var string = 'id='+ id;
$.ajax({
type: "GET",
url: "event.php",
data: string,
cache: false,
success: function(data){
$("#content").html(data);
}
});
}
this is how i call the function:
- <a href="#" onclick="klikevent();">
this is the error that i get when i echo var imgid:
imgid = [object Object]