Reputation: 76
I want to change a innerText of a element using php (I also use jquery); and I've tried this:
<?php
$variable = "Hello";
echo '<script>$('#element').text($variable);</script>'
?>
But it didn't work. I've also tried with:
document.getElementsById('element').innerText = $variable;
Upvotes: 1
Views: 2201
Reputation: 67505
You have a quotes problem as @Robiseb mentioned in the above comment, use :
echo "<script>$('#element').text('" . $variable . "');</script>"
//Or
echo "document.getElementsById('element').textContent = '" . $variable . "';"
Hope this helps.
Upvotes: 2
Reputation: 76
Use
document.getElementById('element').innerHTML = $variable;
or
$('#element').html($variable);
Upvotes: 1