0

I need to change the text to the mouse hover over the buttons i try this code but doesn't work.

<script type="text/javascript">
  jQuery(function($){
    $(".cat-item-13").hover(function () {
     $('#text-digital-solution p').hide().html("<?php echo term_description('13','casestudies_category'); ?>").fadeIn('fast');

    });
 });
</script>

this is error: Uncaught SyntaxError: Unexpected token ILLEGAL

manu
  • 77
  • 7
  • 1
    Can you use the snippet editor to create a real example with HTML? For example what is the content of `term_description('13','casestudies_category');` - if it contains a double quote the statement will fail – mplungjan Nov 11 '15 at 15:12

2 Answers2

0

Try this and tell me if it works:

var test = '<?php echo term_description("13","casestudies_category"); ?>';
 $(".cat-item-13").hover(function () {
     $('#text-digital-solution p').html(test).fadeIn('fast');
    });

I am not sure to be honest if the PHP will be putout correctly, beacuse PHP commands are getting done on pageload.

Marcel Wasilewski
  • 2,519
  • 1
  • 17
  • 34
  • 1
    Will STILL fail if the php text contains single quotes – mplungjan Nov 11 '15 at 15:23
  • yeah you are right, i will correct it... it was a long day today^^ – Marcel Wasilewski Nov 11 '15 at 15:24
  • i try this solution, but doesn't work. where i fail? – manu Nov 11 '15 at 16:00
0

Here is a safer version. I assume you are failing due to quotes or newlines in the text from PHP

The encoding is taken from Pass a PHP string to a JavaScript variable (and escape newlines) - which, if it solves your issue should result in your question being marked as duplicate

$(function(){
  var desc = decodeURIComponent("<?php echo rawurlencode(term_description('13','casestudies_category')); ?>");
  $(".cat-item-13").hover(function () {
    $('#text-digital-solution p').hide().html(desc).fadeIn('fast');
  });
});
Community
  • 1
  • 1
mplungjan
  • 169,008
  • 28
  • 173
  • 236