Another possibility is Using data()
Store arbitrary data associated with the specified element. Returns the value that was set.
$(".svgobjects").on("mousedown", function(){
$(".svgobjects").data("clicked", "yes");
});
alert($(".example").data("clicked"));
For specific object
$(".svgobjects").on("mousedown", function(){
$(this).data("clicked", "yes");
});
Live demo
with the data()
you can store some data to the element
when it being clicked.And retrieve that information ,When you need it :)
Edit after update the Question:
That means you are logging the variable
,before the callback,Which is updating the variable after the logging done.
$(".example").append("<input class='svgobjects'</input>")
var ifclicked=false;
$(".svgobjects").on("mousedown", function(){
console.log("clicked");
ifclicked = true;
alert(ifclicked);
});
console.log("ifclicked "+ifclicked);
Demo for the Edit