I'm developing a chrome extension that injects a button on web page. I'm able to inject the button successfully however i cannot apply a onclick function on it. I wrote button injection code in content.js which is as follows
jQuery('body').append('<button onclick="myFxn();" class="vwsItBtn" style="height: 25px; width: 80px; position: absolute; opacity: 1; font-size: 12px; z-index: 867530999; display: block; padding-right: 4px !important; margin: 0px; border: 2px solid rgb(254, 208, 70); background-color: whitesmoke; border-radius: 4px; font-weight: bolder; text-shadow: #FED046 0px 0px 1px; color: #36373B; text-align-last: end;"><img id="myImgVw" style="width: 15px; display: inline-block; padding: 0px; left: 2px; position: absolute; vertical-align: middle !important; top: 3px;" src="'+chrome.extension.getURL("imgvwextsitbtn.png")+'"/> Schedule</button>');
jQuery(function(){
function myFxn(){
alert('This is working!');
}
})
Now i get an error that myFxn is not defined. Now this function is quite simple but how do i make it work?
This is the first time i'm developing a chrome extension and i'm pretty sure there is some other way of doing it. Please help!!