hiDayurie
hiDayurie

Reputation: 92

Run jQuery function in PHP Function File

How to add jQuery function in PHP function File?

Example :

<script type="text/javascript" src="assets/js/jquery.min.js"></script>
<script type="text/javascript" src="assets/js/jquery.livequery.js"></script>
<script type="text/javascript" src="assets/js/jquery.timeago.js"></script>
<?php
class db{
public $db;

function get_news()
{
bla bla
}
}

When run the code, the jQuery is not working. Please help.

Thank you

Upvotes: 0

Views: 1430

Answers (3)

Aleksandar Vasić
Aleksandar Vasić

Reputation: 593

You can Echo jQuery function call to run it

<?php
echo "<script type=\"text/javascript\">
$(document).ready(function() {
  alert(\"Test\");
 });
</script>";
?>

Upvotes: 0

Vinod VT
Vinod VT

Reputation: 7159

This is a sample code,

<script type="text/javascript" src="assets/js/jquery.min.js"></script>

<script type="text/javascript">
    $(document).ready(function() {
      alert("Test");
     });
</script>

<?php
   echo "PHP code here";
?>

Upvotes: 0

superrafal
superrafal

Reputation: 526

You can't run jQuery function in PHP. You can run them from HTML. First close php:

?>
<script>
    function get_news() { blabla; }
</script>
<?php

If this is not what you're looking for then there is no way for you to do what you're looking for.

Upvotes: 1

Related Questions