admin管理员组文章数量:1405170
I have a stylesheet which indents paragraphs by 20px, but I do not want an indent on the first paragraph after each H4.
So I have something like this:
<p>Paragraph 1</p>
<p>Paragraph 2</p>
<h4>Sub Heading</h4>
<p>Paragraph 3</p>
<p>Paragraph 4</p>
Using jquery I want to override the css on Paragraph 3 so there is no text-indent.
I tried this but nothing happened:
$("#myDiv > h4").next("p").css({"text-indent":0});
I have a stylesheet which indents paragraphs by 20px, but I do not want an indent on the first paragraph after each H4.
So I have something like this:
<p>Paragraph 1</p>
<p>Paragraph 2</p>
<h4>Sub Heading</h4>
<p>Paragraph 3</p>
<p>Paragraph 4</p>
Using jquery I want to override the css on Paragraph 3 so there is no text-indent.
I tried this but nothing happened:
$("#myDiv > h4").next("p").css({"text-indent":0});
Share
Improve this question
asked Jan 31, 2012 at 11:32
TomTom
13k50 gold badges153 silver badges247 bronze badges
5 Answers
Reset to default 12You can do this with just CSS:
#myDiv > h4 + p {
text-indent: 0;
}
That selector means: select p
preceded by h4
that is a child of #myDiv
.
+
is the adjacent sibling selector.
Or as JavaScript if you prefer:
$('#myDiv > h4 + p').css('text-indent', 0);
What about this?
Use h4 + p
as your selector.
many ways are there...
$(document).ready(function(){
$('#myDiv h4').each(function(){
$(this).next().css({"text-indent":0});
});
});
DEMO
$('#myDiv h4').next('p').css({textIndent:0});
$("#myDiv > h4:first-child")css({"text-indent":0});
http://api.jquery./first-child-selector/
本文标签: javascriptAlter the CSS of the first p tag after each H4 tagStack Overflow
版权声明:本文标题:javascript - Alter the CSS of the first p tag after each H4 tag - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744248882a2597153.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论