Reputation: 246
How can I access object foo? I want to pass it to the event listener. Do I have to make foo global?
function test(){
var foo = {
bar:2
}
}
$('#bla').on('click',function(){
foo.bar = 5;
});
Upvotes: 0
Views: 58
Reputation: 598
Try Following
var foo={};
test();
function test(){
foo.bar=2 ;
}
$('#bla').on('click',function(){
foo.bar = 5;
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="button" value="test" id="bla"/>
Upvotes: 1