Sometimes we need to work jQuery with PHP. Actually jQuery works with PHP in the same way as HTML. Let’s take the same text counter example before to see how jQuery works with PHP.

 
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jQuery and PHP First Look</title>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
    $("document").ready(function() {
        
        // Declare variable
        var i = 0;
        
        function loopCounting() {
            
            // increase i by one
            i = i + 1;
        
            // Display message on text field
            $(".outputText").text(i);
        }
        
        // Execute the function in set interval (milli-seconds)
        setInterval(loopCounting, 1000);
                
    });
</script>

</head>

<body>
<h2>First look at jQuery and PHP</h2>

<?php
    echo "Hello! Good luck!  The lucky number is: " . "<span class=\"outputText\"></span>";
?>

</body>
</html>

Demo:

jQuery Example File:

Click here to download.

As we can see jQuery works with PHP in the same way as HTML.