[jQuery] How to select a child element from a saved variable
Hello,
I am using an element many times in sucession and as such don't want
to search the DOM every time. I would like to save the top level
element in a varialble and then use it to repeated access other
elements directly. With this I would like to select a first level
child element of the saved top element. Find and Children both return
all levels of like elements instead of just the next level item.
e.g:
I would like to do the equivalent of:
$("#"+my_element+" > .a_common_element);
The problem is:
var my_jquery_element = $("#"+my_element);
my_jquery_element.find(".a_common_element");
The above returns a list of all lower levels of children
matching .a_common_element, I only want the first level item as per
the initial line of code above.
var my_jquery_element = $("#"+my_element);
my_jquery_element.children(".a_common_element");
This too returns all lower levels of children
matching .a_common_element, I only want the first level item.
I'm sure there is any easy way to do this but I'm stumped as to the
syntax I should use.
Thanks,
ml