I have the following code :
$(".highlight").hover(function(){
$(this).css("background-color","#E3EBC2");
},function(){
$(this).css("background-color","transparent");
});
I was wondering how I could highlight if the immediate child of this class was a paragraph, and add a border if it was an image
<div class = "highlight>
<p>
some text
</p>
</div>
so the immediate child would be the p (only one level down the tree)
One way is to combine a child selector with a first child filter and then use an
iscall to see what you get, something like this:And a live example: http://jsfiddle.net/ambiguous/kSmXQ/
Or, if you want to play with some CSS:
And the jQuery to go with that:
And a live version of this one: http://jsfiddle.net/ambiguous/LPga3/1/
Thanks to Ghostoy for the idea behind this one.
And if you want the background color or border change on the
<div>rather than the<p>or<img>child:Live example of this one: http://jsfiddle.net/ambiguous/ufLaW/