X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fjquery%2Fjquery.js;h=78d1ab94d2c4d60df35b40a659de9e7ee4000ee9;hb=5acecf6e2814701f9e22f91f17fcb33ef910e88a;hp=e38044147702736a15d83d7edbfc674b6fa56d0a;hpb=c78b1fb9a1f44c640290c1ffdb16b0c1d5531b7b;p=jquery.git diff --git a/src/jquery/jquery.js b/src/jquery/jquery.js index e380441..78d1ab9 100644 --- a/src/jquery/jquery.js +++ b/src/jquery/jquery.js @@ -526,10 +526,19 @@ jQuery.fn = jQuery.prototype = { */ /** - * Set the text contents of all matched elements. This has the same - * effect as html(). + * Set the text contents of all matched elements. * - * @example $("p").text("Some new text."); + * Similar to html(), but escapes HTML (replace "<" and ">" with their + * HTML entities. + * + * If stripTags argument is set to true, HTML is stripped. + * + * @example $("p").text("Some new text."); + * @before

Test Paragraph.

+ * @result

<b>Some</b> new text.

+ * @desc Sets the text of all paragraphs. + * + * @example $("p").text("Some new text.", true); * @before

Test Paragraph.

* @result

Some new text.

* @desc Sets the text of all paragraphs. @@ -537,13 +546,12 @@ jQuery.fn = jQuery.prototype = { * @name text * @type String * @param String val The text value to set the contents of the element to. + * @param Boolean stripTags (optional) Wheather to strip or only escape tags * @cat DOM/Attributes */ - text: function(e) { - // A surprisingly high number of people expect the - // .text() method to do this, so lets do it! + text: function(e, stripTags) { if ( typeof e == "string" ) - return this.html( e ); + return this.html( stripTags ? e.replace(/<\/?[^>]+>/gi, '') : e.replace(//g, ">") ); e = e || this; var t = "";