-4

I have jQuery function in a PHP function. I have id of a div in a PHP variable. I want to pass this variable to the jQuery code, but it is not working:

public function food(){
    echo '<script>
    $(document).ready(function () {
        $("#$this->ccid #food").show();
    });
   </script>';
}
Massimiliano Kraus
  • 3,638
  • 5
  • 27
  • 47
Osama Malik
  • 41
  • 1
  • 8

1 Answers1

2

Just use string concatenation:

public function food(){
    echo '<script>
    $(document).ready(function () {
        $("#' .$this->ccid. ' #food").show();
    });
   </script>';
}
Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98
rebecca
  • 943
  • 9
  • 12