1

Very simple question:

Is it possible to display a var in .html, using jQuery?

var inscr = '<?php echo "test"; ?>';
    $j('#myPlaceHolder7').html('<li class="button3">+inscr</li>');

Thanks!

Thanks everyone for the quick help!

4 Answers 4

4

Yup:

$j('#myPlaceHolder7').html('<li class="button3">' + inscr + '</li>');

Just concatenate your var with the enclosing strings, using the + operator.

Sign up to request clarification or add additional context in comments.

Comments

1

Yes, just use the + operator to concatenate the strings.

var inscr = '<?php echo "test"; ?>';
$j('#myPlaceHolder7').html('<li class="button3">' + inscr + '</li>'); 

Comments

1

Yah, try this:

var inscr = '<?php echo "test"; ?>';
$j('#myPlaceHolder7').html('<li class="button3">' + inscr + '</li>');

Now if your var is not a string or simple type, you will need a util to searialize the var. Try JSON2's stringify. This will show your object as JSON.

Comments

1
<script>
var inscr = <?php echo json_encode("test"); ?>;
$j('#myPlaceHolder7').html('<li class="button3">'+inscr+'</li>');
</script>

Results in this source:

<script>
var inscr = "test";
$j('#myPlaceHolder7').html('<li class="button3">'+inscr+'</li>');
</script>

See json_encode()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.