What is a jquery selector, see selector:http://docs.jquery.com/selectors in jquery
such as $ ("Div:contains (' John ')"). CSS ("text-decoration", "Underline"), contains selectors, etc.
Basic syntax for the jquery custom selector:
$.expr[': '].test = function (obj, index, meta, stack) {
/* Obj-is A current DOM element
Index-the current loop, index in stack
Meta-meta data about your selector!!! Used to store parameter values, see Custom selectors with parameters.
Stack-stack of all elements to loops
Return true to include the current element
Return false to explude the current element
*/
};
Usage:
$ ('. Someclasses:test '). dosomething ();
1. Create a simple custom selector (returns an element with a "rel" label that is not empty)
$.expr[': '].withrel = function (obj) {
var $this = $ (obj);
Return ($this. attr (' rel ')! = ');
};
Application:
$ (' A:withrel '). CSS (' background-color ', ' yellow ');
Effect See: http://custom-drupal.com/jquery-demo/custom-selectors/
2. Create a custom selector with parameters, implemented by Meta.
Grammar:
$ (' a:test (argument) ');
The format of Meta would carry the following Info:meta is as follows (Meta[3] corresponding value is argument)
[
': Test (argument) ',//Full Selector
' Test ',//Only Selector
",///Quotes used
' argument '//Parameters
]
$ (' A:test ("arg1, arg2") ');
Meta would carry the following info:
[
': Test (' arg1, arg2 ') ',//Full Selector
' Test ',//Only Selector
' ' ',///Quotes used
' Arg1, arg2 '//Parameters
]
Instance:
$.expr[': '].withattr = function (obj, index, meta, stack) {
Return ($ (obj). attr (meta[3])! = ");
};
Application:
$ (' a:withattr (rel) '). CSS (' background-color ', ' yellow ');