-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,433
  • 5
  • 24
  • 45
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>';
}
Anant Kumar Singh
  • 68,309
  • 10
  • 50
  • 94
rebecca
  • 905
  • 8
  • 12