tags:

views:

35

answers:

2

in jquery we can find inner class or something else with

$("#id xxxxxx")

xx... can be anything.

But i am taking element by this like below:

$(".something").bind("click",function(){
  $(this).find("......
});

and want to take inner element something like : $(this + " .divClassNameOrFilter")

I can take the element with $(this).find(".divClassNameOrFilter)

But after i found something that will be an array and i can't continue with $(this).find(".divClassNameOrFilter).css(.....

I have to take the first element with [0] and wrap it again with $(...) like that: $($(this).find(".divClassNameOrFilter)[0]).css(.....

Is there any way not to do like i said above?

+1  A: 

You can use .eq() like this:

$(this).find(".divClassNameOrFilter").eq(0).css(...);

Or use :first, like this:

$(this).find(".divClassNameOrFilter:first").css(...);

As an aside, there are other filter functions and selectors as well.

Nick Craver
oh, you added extra to make it the same as mine...
redsquare
@redsquare - Was I editing *while* you posted? Not *based on it*, yes...I like my answer to be as complete as possible. I'll always continue to add any relevant information to an answer *as I think of it*. `:first` isn't an obscure selector I've never heard of, I *do* however like to post the link to the API when using functions/selectors, and it takes me a bit longer to edit since I do that.
Nick Craver
first was enough for me but eq(x) is better than first to learn another method... Thanks...
uzay95
@NickCraver - it is fine. Nice context change to the comment above also. It was noted however.
redsquare
Nick Craver
+1  A: 

That should be possible using .first():

$(this).find(".divClassNameOrFilter").first().css(.....
che