Nick Husler
Nick Husler

Reputation: 29

sibling() in js and jquery

I'm just starting out learning javascript along with jquery. I have a set of events which trigger the same function. I pass the value of this into the function ($t). I have two main lines of code. One of which works as it uses this as the selector, but the other I need to use the equivalent of "this p". Ie select this (a div) and all the p s within it. I've tried:

$($t).css({"background-color": "rgba(30,30,30,0.5)"});
$($t p).css({"color": "#ffffff"});

and

$($t).css({"background-color": "rgba(30,30,30,0.5)"});
$($t).sibling("p").css({"color": "#ffffff"});

but I can't seem to get it to work. The top css command works, but the sibling one doesn't. This is exactly how it appears in my code. No commands inbetween them.

Thanks Nick

Upvotes: 0

Views: 136

Answers (3)

Amin AmiriDarban
Amin AmiriDarban

Reputation: 2068

Just use this

$($t).find('p').css({"color": white});

And For Later Try Reading Jquery Documents in Here

Upvotes: 0

rajesh kakawat
rajesh kakawat

Reputation: 10896

try something like this

$("p",$t).css({"color": "#ffffff"});

or

$($t).find( "p").css({"color": "#ffffff"});

Upvotes: 1

adeneo
adeneo

Reputation: 318222

select "this" (a div) and all the "p"s within it.

$('p', $t).css({"color": "#ffffff"});

which is short for :

$($t).find('p').css({"color": "#ffffff"});

siblings() will select... wait for it ..... siblings, not elements within the element, that would be find()

Upvotes: 2

Related Questions