我想在另一個之前渲染一個div。某些js文件在Drupal中不工作
我測試了我本地機器上的js,以確保它通過創建簡單頁面來工作。代碼如下:
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<div id="QWERTY">
<div class="content">
<div class="field-name-field-image-one">IMAGE</div>
<div class="body">BODY</div>
</div>
</div>
<script>$('.content .body').insertBefore('.content .field-name-field-image-one'); // check before() examples</script>
</body>
</html>
我已經添加下面的代碼到一個js文件在我的Drupal網站:
(function ($, Drupal, window, document, undefined) {
$('.content .body').insertBefore('.content .field-name-field-image-one'); // check before() examples
})(jQuery, Drupal, this, this.document);
我.info文件鏈接到js和它加載。其他需要javascript的元素也在工作。我甚至嘗試在html.tpl文件中添加腳本,但那也不起作用。
我試圖影響的div嵌套在html標記的深處,並且與我所做的簡單版本相比,它們有幾個類適用於它們。這可能是原因嗎?我不夠具體嗎?