javascriptphpjqueryhtmljquery-append

How to append add php conditions while replacing html text in jquery


basically , when document is ready , I would like to replace the td content with this html content that has some php conditions in it as shown below , but it's not working

<?php
 echo "<script type='text/javascript'>";
 echo "$(document).ready(function(){";
 ?>
 $('#redeem_freebie).html('<a class="btn" <? if (!$freebies->expired) {?>onclick="applyFreebieNow('<?=addslashes($dialog_copy)?>','<?=addslashes($freebies->get_started_link)?>','<?=$freebies->promo_code_id?>');"<? } ?> style="<?=$freebies->expired ? 'cursor: default;':''?>">Redeem Freebie &gt;&gt;</a>');
<?php 
 echo "});";    
 echo "</script>";
 echo "}";

?>

Solution

  • <script type='text/javascript'>
    $(document).ready(function(){
        $('#redeem_freebie').html('<a class="btn" <?php if (!$freebies->expired) {?>onclick="applyFreebieNow('<?php echo addslashes($dialog_copy); ?>','<?php echo addslashes($freebies->get_started_link)?>','<?php echo $freebies->promo_code_id?>');"<?php } ?> style="<?php echo $freebies->expired ? 'cursor: default;':''?>">Redeem Freebie &gt;&gt;</a>');
     });   
     </script>
    

    Some hint : dont use <?= really not clear and your error was here <? } ?> <- php short tag