- Improved docs for append, prepend, before and after, merging the three pairs into one
- Improved show/hide animations to show only hidden and hide only visible elements
- Added attr(String,Function) to calculate the value and support for attr("key", "${formula}") syntax, a shortcut for the former
+ - text(String) now escapes HTML per default and optionally stris tags completely
1.0.4
-----
ok( $('#mark').removeAttr("class")[0].className == "", "remove class" );\r
});\r
\r
+test("text(String, Boolean)", function() {\r
+ ok( $("#foo").text("<div><b>Hello</b> cruel world!</div>")[0].innerHTML == "<div><b>Hello</b> cruel world!</div>", "Check escaped text" );\r
+ ok( $("#foo").text("<div><b>Hello</b> cruel world!</div>", true)[0].innerHTML == "Hello cruel world!", "Check stripped text" );\r
+});
\ No newline at end of file
*/
/**
- * 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("<b>Some</b> new text.");
+ * @before <p>Test Paragraph.</p>
+ * @result <p><b>Some</b> new text.</p>
+ * @desc Sets the text of all paragraphs.
+ *
+ * @example $("p").text("<b>Some</b> new text.", true);
* @before <p>Test Paragraph.</p>
* @result <p>Some new text.</p>
* @desc Sets the text of all paragraphs.
* @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, "<").replace(/>/g, ">") );
e = e || this;
var t = "";