Date: 2009oct28
Language: javaScript, perl
Q. What's a nice way to embed jQuery in perl?
A. In perl you might have inline jQuery like this:
# DOES NOT WORK
print <<EOF;
<script>
$(document).ready(function() {
$('#datepicker').datepicker();
});
</script>
EOF
But this doesn't work because perl will interpret the $ as the start of
a variable name and try to interpret it. So you can escape the dollar
symbols from perl like this:
# WORKS BUT UGLY
print <<EOF;
<script>
\$(document).ready(function() {
\$('#datepicker').datepicker();
});
</script>
EOF
That's ugly.
But, the dollar is just an alias for "jQuery" so you can do this:
# WORKS AND PRETTY
print <<EOF;
<script>
jQuery(document).ready(function() {
jQuery('#datepicker').datepicker();
});
</script>
EOF
Which works and is clearer.