labu77 labu77 - 8 months ago 96
HTML Question

Add javascript with jQuery

When a div has zero height, I try to add a javascript code.


<div class="med_rec"></div>


if ($(".med_rec").height() === 0) {

$('.med_rec').text('<script type="text/javascript" src="//"></script>
<script type="text/javascript">
"zoneid": 11111,
"async": false});


I tried it with

</' + 'script>

but there is always a syntax error.

Thank you

Answer Source

Apparently the problem was with : '<' and '>'

Use this:

$('.med_rec').append('\<script type="text/javascript"  src="//"\>\</script\><script type="text/javascript">Criteo.DisplayAd({"zoneid": 11111,"async": false});\</script\>');

I hope it helps