Rank
Rank

Reputation: 59

Jquery fill in content of div

I have the following code:

<div class=“phpversion”></div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>

<script>
            $(document).ready(function() {
                $.ajax({
                    url:"/core/components/seo/templates/default/functions/generic/php-version.php",
                    success:function(result){
$( "div.phpversion” ).html(result);
                    }
                });             
            });
</script>

The aim is to fill in the div with class phpversion with the result obtained.

When I use "alert(result);" instead of "$( "div.phpversion” ).html(result);", the popup box with the expected value displays on load of the page.

Can you please help :) ?

Upvotes: 1

Views: 956

Answers (2)

Damien Ferey
Damien Ferey

Reputation: 99

It's because you're using wrong double-quote symbol. You're using the “ symbol instead of " symbol (3 times in your snippet)

Upvotes: 1

Marcin
Marcin

Reputation: 1494

Use ID for that div and update the JavaScript code accordingly:

<div id="phpversion"></div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>

<script>
            $(document).ready(function() {
                $.ajax({
             url:"/core/components/seo/templates/default/functions/generic/php-version.php",
                    success:function(result){
$( "#phpversion" ).text(result);
                    }
                });             
            });
</script>

Upvotes: 0

Related Questions