I have below PHP Function contains some Javascript code the function work perfectly. But the javascript code only works in first PHP call function. When I call a function in another place for the second time the javascript code remains as the first call and don't change according to the second call data.
<?php
function YPE_bsn_font() { ?>
<select id="fonts">
<option value="">Font one</option>
<option value="">Font two</option>
</select>
<div class="textloader">
<?phpecho __('The Quick Brown Fox Jumps Over The Lazy Dog. 1234567890');?>
</div>
<style id="bsn-font-loader" type="text/css">
.textloader {border:1px solid #ddd;margin:5px 0 0;padding:10px;background:#f8f8f8;}
</style>
<script>
jQuery(document).ready(function($) {
$("#fonts").change(function() {
var optionName = $("#fonts option:selected").text();
var fontName = optionName.split(' ').join('-');
$('.textloader').attr('id', ''+fontName+'');
$("#bsn-font-loader").text('#'+fontName+' {font-family: "'+ optionName +'"}');
});
});
</script><?php
}
?>