以下はHTMLコードです
<div id="Parent">
This is Parent Div
<p> This is first child.</p>
<p> This is second child.</p>
<p> This is Third child.</p>
</div>
<input type="button" id="clickme" value ="click me" />
ここにjQueryコードがあります
$('#clickme').click(function() {
$('#Parent')
.children() // 1st phase action on children begins here
.css('color', 'blue')
.end() //Here 1st phase action on children ends
.css({
'color': 'red',
'border-color': 'blue',
'border-width': '3px',
'border-style': 'solid'
}) // Here 1st phase action on Parent completed
.children() //2nd phase action on children begins
.css({
'border-color': 'red',
'border-width': '2px',
'border-style': 'solid'
}).end() // 2nd phase action on children ends
.css('font-style', 'italic'); //2nd phase action on parent begin/ends
});
上記の jquery コードでは、子と親に異なるスタイルを適用しようとしています。斜体スタイル以外はすべて正常に機能します。なぜこの奇妙なことが起こるのか、誰か説明してくれませんか?
申し訳ありませんが、これを逃しました - 親にイタリック体を適用していますが、子も変更されます。これを防ぐ方法は?