0

I am trying to select some elements on my page based on some conditions... and these all have some common parents as follow:

$("[id*=wizard_person]:not(.hidden) select.required, [id*=wizard_person]:not(.hidden) input.required:not(.tt-hint)").each ->
    ...

Here, I'm selecting both input.required:not(.tt-hint) and select.required that are present in [id*=wizard_person]:not(.hidden).

However, I'm writing [id*=wizard_person]:not(.hidden) twice, to handle both scenarios.

Is there a way I can DRY this up? if yes, How? thanks.

2
  • can you try like this $("select.required,input.required:not(.tt-hint) , [id*=wizard_person]:not(.hidden)") Commented Sep 7, 2016 at 3:36
  • Why would you want to target [id*=wizard_person]:not(.hidden)? The OP is trying to target specific input and select descendants Commented Sep 7, 2016 at 3:49

1 Answer 1

1

I would start from [id*=wizard_person]:not(.hidden) and then find the correct descendants:

$("[id*=wizard_person]:not(.hidden)").find("select.required, input.required:not(.tt-hint)").each(...)

If your selects and inputs are direct children, you could even use children() instead of find()

Sign up to request clarification or add additional context in comments.

1 Comment

awesomely neat and precise, what I wanted.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.