当子 div (ezblog-head) 存在时,我需要更改父 div (content-indent) 的背景图像。我在网上找到了很多答案。但我似乎无法让他们中的任何一个工作。
实际的 index.php 页面如下所示:(该站点是使用 Joomla 构建的)
<div class="content-indent">
<jdoc:include type="component" />
</div>
在浏览器中加载为:
<div class="content-indent">
<!-- bunch of other stuff -->
<div id="ezblog-head>
<!-- more stuff -->
</div>
</div>
这是我在索引页面上使用的 Javascript(它不起作用)
<script type="text/javascript">
if ($('#ezblog-head')[0]){
<style>
.content-indent {background: #0f0;}
</style>
}
</script>`
我也试过这个(无济于事):
<script type="text/javascript">
if (document.getElementById("ezblog-head")) {
document.getElementByClass('content-indent').style.background ='#0f0'
}
</script>
任何帮助将不胜感激。谢谢!