Elggetto
Elggetto

Reputation: 237

Selectors in jquery problems

My problem is quite simple. What I want to do in jquery is something like this:

$(this > ".otherDiv").show();

But it doesn't work and I have no idea why. I also tried:

$(this).$(".otherDiv").show();
$(this + ".otherDiv").show();
$(this ".otherDiv").show();
$(this.".otherDiv").show();

It works when I replace this with something else. And I tested and this is really the parent div I want. Is there something i'm doing wrong?

Thx!

Upvotes: 1

Views: 60

Answers (4)

Šime Vidas
Šime Vidas

Reputation: 185933

This is the correct form:

$(this).children('.otherDiv').show();

Upvotes: 1

Damien-Wright
Damien-Wright

Reputation: 7544

My personal favourite is:

$(".otherDiv", this).show();

Which is an elegent, shorthand way of writing:

$(this).find('.otherDiv').show ();

Hope that helps :)

Upvotes: 1

Matt Enright
Matt Enright

Reputation: 7484

this is not a jquery object, it is a Javascript one. Try something like this:

$(this).find('.otherDiv').show ();

Upvotes: 1

qwertymk
qwertymk

Reputation: 35284

$(this).find(".otherDiv").show();

Upvotes: 1

Related Questions