I'm just trying to change the background color of all "h1" elments present under "p" as below but it's not working
$(document).ready(function(){
$("p").find("h1").css("background-color","yellow");
});
Below is jsfiddle
I'm just trying to change the background color of all "h1" elments present under "p" as below but it's not working
$(document).ready(function(){
$("p").find("h1").css("background-color","yellow");
});
Below is jsfiddle
your html markup is invalid. Look at the markup generated with a debugger:
<p>first
</p><h1>first h1 <span>span1
<h1>another h1 inside span</h1>
</span>
</h1>
<p></p>
seems you can't have a h* inside a p
it's working.
See Nesting block level elements inside the <p>
tag… right or wrong?:
No, a paragraph element may not contain other block elements.
A paragraph tag is intended for a block of text. If your elements is a part of the text (and not block elements), it would be semantically correct, otherwise not. A span tag with display:block is still a block element.
Most browsers are going to remove the h1 tags from the p tags so it's not going to work. Using a span and styling it like an H1 will work just as good. Also your markup was a bit chaotic, I would suggest cleaning it up.
` tag is legal within a `
` tag, according to this: https://developer.mozilla.org/en/HTML/Element/h1. I tried to play with your fiddle to give you an answer, but it seems to be doing strange things with a header within a paragraph.
– FishBasketGordo Jul 11 '11 at 14:59