I need selectors which are able to retrieve correct results for visual closeness queries like the following:
$("h2:closestTo('div#example')");$("input:below('label:contains(\"Username\")')");
Closeness and distances should be dependent of the visual location of elements rendered in the web browser (and differs for different window sizes).
Is there any way to do that with jQuery? I think it will involve the usage of .offset()
I just created a first working version by myself.
Demonstration: http://jsfiddle.net/alp82/L5ZM8/
Definition of “above”: Only elements which are visually above a reference element are returned. Also, they have to be in horizontal bounds of the reference elements. The same rules apply to “below”, “leftTo” and “rightTo”.
Here is the code:
Use the selector like in the following examples. The argument to the custom selector has to be a selector which returns exactly one element:
Please tell me if that works for you and/or you have suggestions to make it better.