Reputation: 23
I am changing anchor tag text once it is clicked using jquery (replaceWith
) and it is working fine. But it also replaces the css of the anchor tag text.
Can anyone help me how not to replace css or add it again.
My html is as follows:
<div class="col-xs-12 col-md-12" >
<a class="btn btn-lg btn-success deal" target="_blank" style="width:100%;background:#b71c1c;" rel="nofollow, noindex"
href="<?= $coin["link"]; ?>" >
<b>Get Offer</b>
</a>
</div>
and code:
$(document).ready(function(){
$('.deal').click(function(){
$(this).replaceWith("<?php echo $coin['coupon_code']; ?>");
});
});
Upvotes: 0
Views: 123
Reputation: 2655
If <?php echo $coin['coupon_code']; ?>
contains html
tags use
$(this).find('b').html('<?php echo $coin['coupon_code']; ?>');
Or if it is plain text use
$(this).find('b').text('<?php echo $coin['coupon_code']; ?>');
If you don't want bold remove .find('b')
Upvotes: 1
Reputation: 2104
If you just want to replace the content of the inner <b>
tag, this is your best option:
$('.deal').click(function(){
$(this).find('b').text('<?php echo $coin['coupon_code']; ?>');
});
Upvotes: 0
Reputation: 391
Try this, you just need to change text.
$(this).html("<?php echo '<b>'.$coin['coupon_code'].'</b>'; ?>");
Upvotes: 0