Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By niccolo.mineo on
Hi guys, I am trying to insert the value of a field (which is an image URL) in a CSS property. I am doing it through JS. This whole code will go in a theme file.
I am wondering whether something like this is correct in Drupal:
drupal_add_js('jQuery(document).ready(function () {
$(".myDiv")
.css({"background":"url("
. render($content['myField']) .
")"})
});', 'inline');
Comments
=-=
shouldn't add directoly to tpl.php files see: https://www.drupal.org/node/756722 for how to manage js in Drupal.