Button inserted using javascript repeats if a sub table is refreshed

I have used the following code to insert a "Create Report" button which merges fields to webmerge. My problem is that whenever a subtable in my scene gets added to, another button appears in the scene. This happens each time and therefore the user ends up with lots of "Create Report" buttons. How do I stop this please?

$(document).on('knack-scene-render.scene_52', function(event, scene) {

$('#view_155').after('<div style="padding:0px"><a href="#" id="webmerge" class="kn-button">Create Report</a></div>');

// link hander: Print Report
$('#webmerge').click(function(event) {
event.preventDefault();

Thanks in advance

Kim

you could also use 

$(document).one('knack-scene-render.scene_52', function(event, scene) {.........

This will only execute one time

Sunny thank you soooo much! I am learning JS as I go and so grateful for your help!

Hello Kim,

 

just add a check 

 

$(document).on('knack-scene-render.scene_52', function(event, scene) {
if($("#webmerge").is(":visible")==false)
$('#view_155').after('<div style="padding:0px"><a href="#" id="webmerge" class="kn-button">Create Report</a></div>');