NietzscheProgrammer NietzscheProgrammer - 5 months ago 15
Javascript Question

jQuery is not overwriting text coming from php include

I have a php file coming from a global assets folder, in the footer I have this:

<?php
include('../global/includes/footer_template.php');
?>


and in that template I have something like this:

<a href="<?php echo $legalUrl;?>"target="_blank">
<?php echo ($isLangSpanish?'Nota Legal':'Legal Notices');?>
</a>


so in the view you will see 'Legal Notices', for one of the pages the client is asking me to uncapitalize the 'N' in Notices. So I did this with jQuery

<?php
include('../global/includes/footer_template.php');
?>

<script type="text/javascript">
$(document).ready(function(){
$('.footer p a').text().replace('Notices', 'notices');
});
</script>


And it works in the browser console:

enter image description here

But I can't see that change in the view.

What can I do?

NOTE:
I can't change the footer template in the assets because it's been used for other projects.

Answer

You have to assign the value back.

$(document).ready(function(){
    $('.footer p a').text($('.footer p a').text().replace('Notices', 'notices'));
});

a little cleaner:

$(document).ready(function(){
    var link = $('.footer p a'),
        updatedText = link.text().replace('Notices', 'notices');
    link.text(updatedText);
});