Problem . Given the specific element of the container container (window, div, set of fields, etc.), find all the elements of the class (.FormWidget) inside this DOM element, recursively search through everything from these container descendants. Include, but do not look inside , elements with the corresponding class (.FormWidget). Elements can be nested in n levels.
For example, given this HTML:
<fieldset id="MyFieldset" class="FormWidget FieldSetMultiplier"> <legend>My Legend</legend> <div> <label for="Field1">Field1</label> <input type="text" name="Field1" value="" id="Field1" class="BasicInput FormWidget"> </div> <div id="SomeWidget" class="FormWidget"> <label for="Field2">Field2</label> <div name="Field2" id="Field2" class="FormWidget RestrictedComboBox"></div> <input type="text"> </div> </fieldset> <div> <label for="Field3">Field3</label> <input type="text" name="Field3" value="" id="Field3" class="BasicInput FormWidget"> </div>
Example 1:
Let the pseudo Jquery function “.findButNotInside ()” represent the functionality I'm looking for.
$(document).findButNotInside('.FormWidget');
Should return only #MyFieldset and # Field3. Starting from the window, fields 1 and 2 and #SomeWidget are FormWidgets, but they cannot be enabled because the function cannot look through other .FormWidgets to find FormWidgets. Everything inside the .FormWidget field is disabled.
Example 2:
$('#MyFieldset').findButNotInside('.FormWidget');
Only #Field1 and #SomeWidget should be returned. It should search for .FormWidget inside the target field, #MyFieldset , but should not return # Field2 because it is not allowed to search inside .FormWidget (in this case #SomeWidget) to find other .FormWidgets.
I think this can be done with the correct function and selector, but I'm not sure how this selector should be constructed?
javascript jquery
Nick
source share