jquery php变量

I have a variable hard coded in to my html inside script tags like this(it calls meta information from a wordpress post and I've checked that the meta is being pulled)

<script type="text/javascript">
   var jg_product_price = "<?php echo get_post_meta($post->ID , 'productprice' , true); ?>";
</script>

my jquery code reads;

.prepend('<span>'+jg_product_price+'</span>');

the html output is:

<span></span>

i.e an empty span

Is it something to do with the "'" in the var jg_product_price? Many thanks

It looks like jg_product_price is empty. Have a look at

alert(jg_product_price);

or view the source code of the page. Make sure get_post_meta($post->ID , 'productprice' , true); is not empty.

  1. Open the resulting page in Firebug (or whatever) and check what, if anything, the php actually outputs into the source.
  2. Try hard coding the value: var jg_product_price = "test";.
  3. Try hard coding the value in php: var jg_product_price = "<?php echo "test2"; ?>".