我有以下代码(https://jsfiddle.net/weemoLya/3/):
<div style="padding: 0px 41px 14px; line-height: 15pt;"><span style="font-family: georgia;">Anwoarnoernb bneobnoqbno nb bnorgneoüqrgn beoünbeoütnboetuübn nbwetiobnweoütnho übnoet wübn weton<br />
otnwboün boenbhiowt nb etiopwogj weto getiogei oeghqeogje ghqeoü gheoügneoqüh<br />
<br />
Ihre Aufgaben:</span></div>
<ul>
<li style="padding: 0px 41px 14px;">test</li>
<li style="padding: 0px 41px 14px;">test2</li>
</ul>
我想更改 div 框的内边距。但因为我在一个框架中,所以我不能只在 html 代码中更改它。我需要通过 javascript 更改它。其实div框有很多,不只这个一个。但是我想要更改的div-box没有ID,所以我不能只更改这一个DIV。
但是我想更改 <ul>
前面的每个 DIV。 -标签。这可能吗?
具体来说:
- 搜索所有 ul 标签
- 查找 DOM 中 ul 标签之前的 div
- 更改此 div 框的内边距。
更新:
我真的忘了提,我需要一个没有 JQuery 的解决方案。抱歉。
最佳答案
您可以用作选择器和方法:
$('div + ul').prev().css('padding', 0)
-jsFiddle-
或者仍在 jQuery 中:
$('ul').prev('div').css('padding', 0) // i guess it would be slower, if it really matters...
关于javascript - 更改 DOM 中 UL 元素之前的 Div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38015737/