[jQuery] How to get parent element and not break a DOM hierarchy

[jQuery] How to get parent element and not break a DOM hierarchy


Hi all!
I am new to jquery. I have a problem to get first parent element
without breaking a hierarchy.
Example:
<div class="ajaxmain">
<div class="somediv">
</div>
<div class="ajaxform">
<span>Hello World</span>
</div>
</div>
I'a trying this:
$('span').parents('.ajaxform, .ajaxmain').get(0); - this is
heirarchically OK, it returns div.ajaxform
but when I'am trying this or change divs order
$('span').parents('.ajaxmain, .ajaxform').get(0); - it returns me
div.ajaxmain
The divs with classes can have different orders. I am working on ajax
form framework based on jquery where the form is send by ajax and
result is set to the nearest ajax div.
Thanks for help.
Michael Zahradnicek