Added Yehuda's selector engine improvements (it's now trivial to add in your own...
[jquery.git] / src / jquery / jquery.js
index 358c165..d22d136 100644 (file)
@@ -487,7 +487,27 @@ jQuery.fn = jQuery.prototype = {
         * @type String
         * @cat DOM
         */
+
+       /**
+        * Set the text contents of all matched elements. This has the same
+        * effect as calling .html() with your specified string.
+        *
+        * @example $("p").text("Some new text.");
+        * @before <p>Test Paragraph.</p>
+        * @result <p>Some new text.</p>
+        *
+        * @param String val The text value to set the contents of the element to.
+        *
+        * @name text
+        * @type String
+        * @cat DOM
+        */
        text: function(e) {
+               // A surprisingly high number of people expect the
+               // .text() method to do this, so lets do it!
+               if ( typeof e == "string" )
+                       return this.html( e );
+
                e = e || this;
                var t = "";
                for ( var j = 0; j < e.length; j++ ) {
@@ -1453,20 +1473,24 @@ jQuery.extend({
                        "^=": "z && !z.indexOf(m[4])",
                        "$=": "z && z.substr(z.length - m[4].length,m[4].length)==m[4]",
                        "*=": "z && z.indexOf(m[4])>=0",
-                       "": "z"
+                       "": "z",
+                       _resort: function(m){
+                               return ["", m[1], m[3], m[2], m[5]];
+                       },
+                       _prefix: "z=jQuery.attr(a,m[3]);"
                },
                "[": "jQuery.find(m[2],a).length"
        },
 
-  /**
+       /**
         * All elements on a specified axis.
         *
         * @private
         * @name $.sibling
         * @type Array
         * @param Element elem The element to find all the siblings of (including itself).
-   * @cat DOM/Traversing
-   */
+        * @cat DOM/Traversing
+        */
        sibling: function( n, elem ) {
                var r = [];
 
@@ -1711,7 +1735,8 @@ jQuery.extend({
                        value: "value",
                        disabled: "disabled",
                        checked: "checked",
-                       readonly: "readOnly"
+                       readonly: "readOnly",
+                       selected: "selected"
                };
                
                // IE actually uses filters for opacity ... elem is actually elem.style
@@ -1785,8 +1810,8 @@ jQuery.extend({
 
                                if ( m ) {
                                        // Re-organize the first match
-                                       if ( !i )
-                                               m = ["",m[1], m[3], m[2], m[5]];
+                                       if ( jQuery.expr[ m[1] ]._resort )
+                                               m = jQuery.expr[ m[1] ]._resort( m );
 
                                        // Remove what we just matched
                                        t = t.replace( re, "" );
@@ -1817,7 +1842,7 @@ jQuery.extend({
 
                                // Build a custom macro to enclose it
                                eval("f = function(a,i){" +
-                                       ( m[1] == "@" ? "z=jQuery.attr(a,m[3]);" : "" ) +
+                                       ( jQuery.expr[ m[1] ]._prefix || "" ) +
                                        "return " + f + "}");
 
                                // Execute it against the current filter
@@ -2602,6 +2627,7 @@ jQuery.macros = {
 
                /**
                 * Get the html contents of the first matched element.
+                * This property is not available on XML documents.
                 *
                 * @example $("div").html();
                 * @before <div><input/></div>
@@ -2614,6 +2640,7 @@ jQuery.macros = {
 
                /**
                 * Set the html contents of every matched element.
+                * This property is not available on XML documents.
                 *
                 * @example $("div").html("<b>new stuff</b>");
                 * @before <div><input/></div>