# jquery-nearby **Repository Path**: jempson/jquery-nearby ## Basic Information - **Project Name**: jquery-nearby - **Description**: jQuery Nearby Plugin - **Primary Language**: JavaScript - **License**: MIT - **Default Branch**: master - **Homepage**: http://git.oschina.net/terrason/jquery-nearby - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2018-03-20 - **Last Updated**: 2021-11-03 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README Which HTML Attribute do I hate the most? That is `id`. I wrote this to avoid querying element by id. This is a jQuery plugin to find the element matching a selector that is somewhere nearby :-) Image a scenario of User Mobile Binding: ```html
``` Use Jquery Nearby to help you: ```javascript var $element=$("#js-smscode");//the base point of searching $element.nearby(1); //equals to `.siblings(":eq(1)")` $element.nearby("#binding-mobile"); $element.nearby('input[name="mobile"]'); $element.nearby("mobile"); // equals to `.nearby("[name=mobile]")` ``` The above all found `#binding-mobile` element. Especially the `.nearby(name)` form works gracefully, Simple string parameter that test failed with `/^#/` or `/[.[>~:]/` is considered to name, EXCEPT: ``` body|form|select|input|textarea|div|span|h\d|table|tr|td|th|p|header|section|fieldset ``` Jquery Nearby find out the target through these steps: 1. If parameter is int then just call `.siblings(":eq()")` instead. 2. Else if parameter is start with `#` then find global document. (Contains same id in one page is your fault :<) 3. Else find from closest `.form-group`. 4. If find nothing, go more far, and find from closest `form` context. 5. If find nothing, continue findind from closest `.dialog` context. 6. Finally, find from global document. So at last Jquery Nearby WON'T return `undefined|null|false` , it returns EMPTY JQUERY object if found nothing.