chackerian chackerian - 10 months ago 30
Javascript Question

How to "enhance" jQuery search with $(this)?

I'm looping over the children of a certain div.

Depending on whether the children are odd or even I have different following operations.

I want to use jQuery's $(this) to get the current context and ADD to the query depending on its state of being odd or even.

If it is an even child I want to get the a child of that div (so this is a child of a child from the loop). How can I do this?

My current method does not work

// This way of adding the child a doesn't work
if (a%2) console.log( $($(this) + " > a"))

else console.log("info")


$($(this) + " > a") is trying to concatenate an object and a string which you can't do.

Use $(this).find('a') instead