LS_
LS_

Reputation: 7129

append a value to $(this) in order to refer to another element

Using jQuery is it possible to append another value to $(this) in order to refer for example to a child element? What I need is something like this:

$(this + " div").remove(".cover");

But the syntax + " div" doesn't work, is there a way to do this using jQuery?

Upvotes: 1

Views: 39

Answers (2)

billyonecan
billyonecan

Reputation: 20260

You need to provide this as the context in which to look for the div, eg:

$('div', this).remove('.cover');

Which is equivelant to $(this).find('div').remove('.cover')

From the documentation:

Internally, selector context is implemented with the .find() method, so $( "span", this ) is equivalent to $( this ).find( "span" ).

Upvotes: 2

Curtis
Curtis

Reputation: 103368

You're trying to find children div elements of this element, and therefore you can use:

$(this).find("div").remove(".cover");

Upvotes: 3

Related Questions