ok( expected == $('#sap').text(), "Check for appending of jQuery object" );\r
});\r
\r
+test("appendTo(String|Element|Array<Element>|jQuery)", function() {\r
+ expect(5);\r
+ var defaultText = 'Try them out:'\r
+ $('<b>buga</b>').appendTo('#first');\r
+ ok( $("#first").text() == defaultText + 'buga', 'Check if text appending works' );\r
+ ok( $('<option value="appendTest">Append Test</option>').appendTo('#select3').parent().find('option:last-child').attr('value') == 'appendTest', 'Appending html options to select element');\r
+ \r
+ reset();\r
+ expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";\r
+ $(document.getElementById('first')).appendTo('#sap');\r
+ ok( expected == $('#sap').text(), "Check for appending of element" );\r
+ \r
+ reset();\r
+ expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";\r
+ $([document.getElementById('first'), document.getElementById('yahoo')]).appendTo('#sap');\r
+ ok( expected == $('#sap').text(), "Check for appending of array of elements" );\r
+ \r
+ reset();\r
+ expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";\r
+ $("#first, #yahoo").appendTo('#sap');\r
+ ok( expected == $('#sap').text(), "Check for appending of jQuery object" );\r
+});\r
+\r
test("prepend(String|Element|Array<Element>|jQuery)", function() {\r
expect(5);\r
var defaultText = 'Try them out:'\r
ok( expected == $('#sap').text(), "Check for prepending of jQuery object" );\r
});\r
\r
+test("prependTo(String|Element|Array<Element>|jQuery)", function() {\r
+ expect(5);\r
+ var defaultText = 'Try them out:'\r
+ $('<b>buga</b>').prependTo('#first');\r
+ ok( $('#first').text() == 'buga' + defaultText, 'Check if text prepending works' );\r
+ ok( $('<option value="prependTest">Prepend Test</option>').prependTo('#select3').parent().find('option:first-child').attr('value') == 'prependTest', 'Prepending html options to select element');\r
+ \r
+ reset();\r
+ expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";\r
+ $(document.getElementById('first')).prependTo('#sap');\r
+ ok( expected == $('#sap').text(), "Check for prepending of element" );\r
+\r
+ reset();\r
+ expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";\r
+ $([document.getElementById('yahoo'), document.getElementById('first')]).prependTo('#sap');\r
+ ok( expected == $('#sap').text(), "Check for prepending of array of elements" );\r
+ \r
+ reset();\r
+ expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";\r
+ $("#yahoo, #first").prependTo('#sap');\r
+ ok( expected == $('#sap').text(), "Check for prepending of jQuery object" );\r
+});\r
+\r
test("before(String|Element|Array<Element>|jQuery)", function() {\r
expect(4);\r
var expected = 'This is a normal link: bugaYahoo';\r
ok( expected == $('#en').text(), "Insert jQuery before" );\r
});\r
\r
+test("insertBefore(String|Element|Array<Element>|jQuery)", function() {\r
+ expect(4);\r
+ var expected = 'This is a normal link: bugaYahoo';\r
+ $('<b>buga</b>').insertBefore('#yahoo');\r
+ ok( expected == $('#en').text(), 'Insert String before' );\r
+ \r
+ reset();\r
+ expected = "This is a normal link: Try them out:Yahoo";\r
+ $(document.getElementById('first')).insertBefore('#yahoo');\r
+ ok( expected == $('#en').text(), "Insert element before" );\r
+ \r
+ reset();\r
+ expected = "This is a normal link: Try them out:diveintomarkYahoo";\r
+ $([document.getElementById('first'), document.getElementById('mark')]).insertBefore('#yahoo');\r
+ ok( expected == $('#en').text(), "Insert array of elements before" );\r
+ \r
+ reset();\r
+ expected = "This is a normal link: Try them out:diveintomarkYahoo";\r
+ $("#first, #mark").insertBefore('#yahoo');\r
+ ok( expected == $('#en').text(), "Insert jQuery before" );\r
+});\r
+\r
test("after(String|Element|Array<Element>|jQuery)", function() {\r
expect(4);\r
var expected = 'This is a normal link: Yahoobuga';\r
ok( expected == $('#en').text(), "Insert jQuery after" );\r
});\r
\r
+test("insertAfter(String|Element|Array<Element>|jQuery)", function() {\r
+ expect(4);\r
+ var expected = 'This is a normal link: Yahoobuga';\r
+ $('<b>buga</b>').insertAfter('#yahoo');\r
+ ok( expected == $('#en').text(), 'Insert String after' );\r
+ \r
+ reset();\r
+ expected = "This is a normal link: YahooTry them out:";\r
+ $(document.getElementById('first')).insertAfter('#yahoo');\r
+ ok( expected == $('#en').text(), "Insert element after" );\r
+\r
+ reset();\r
+ expected = "This is a normal link: YahooTry them out:diveintomark";\r
+ $([document.getElementById('mark'), document.getElementById('first')]).insertAfter('#yahoo');\r
+ ok( expected == $('#en').text(), "Insert array of elements after" );\r
+ \r
+ reset();\r
+ expected = "This is a normal link: YahooTry them out:diveintomark";\r
+ $("#mark, #first").insertAfter('#yahoo');\r
+ ok( expected == $('#en').text(), "Insert jQuery after" );\r
+});\r
+\r
test("end()", function() {\r
- expect(2);\r
+ expect(3);\r
ok( 'Yahoo' == $('#yahoo').parent().end().text(), 'Check for end' );\r
ok( $('#yahoo').end(), 'Check for end with nothing to end' );\r
+ \r
+ var x = $('#yahoo');\r
+ x.parent();\r
+ ok( 'Yahoo' == $('#yahoo').text(), 'Check for non-destructive behaviour' );\r
});\r
\r
test("find(String)", function() {\r
expect(1);\r
ok( $("#foo").text("<div><b>Hello</b> cruel world!</div>")[0].innerHTML == "<div><b>Hello</b> cruel world!</div>", "Check escaped text" );\r
});\r
+\r
+test("$.each(Object,Function)", function() {\r
+ expect(8);\r
+ $.each( [0,1,2], function(i, n){\r
+ ok( i == n, "Check array iteration" );\r
+ });\r
+ \r
+ $.each( [5,6,7], function(i, n){\r
+ ok( i == n - 5, "Check array iteration" );\r
+ });\r
+ \r
+ $.each( { name: "name", lang: "lang" }, function(i, n){\r
+ ok( i == n, "Check object iteration" );\r
+ });\r
+});\r
+\r
+test("$.prop", function() {\r
+ expect(2);\r
+ var handle = function() { return this.id };\r
+ ok( $.prop($("#ap")[0], handle) == "ap", "Check with Function argument" );\r
+ ok( $.prop($("#ap")[0], "value") == "value", "Check with value argument" );\r
+});\r
+\r
+test("$.className", function() {\r
+ expect(6);\r
+ var x = $("<p>Hi</p>")[0];\r
+ var c = $.className;\r
+ c.add(x, "hi");\r
+ ok( x.className == "hi", "Check single added class" );\r
+ c.add(x, "foo bar");\r
+ ok( x.className == "hi foo bar", "Check more added classes" );\r
+ c.remove(x);\r
+ ok( x.className == "", "Remove all classes" );\r
+ c.add(x, "hi foo bar");\r
+ c.remove(x, "foo");\r
+ ok( x.className == "hi bar", "Check removal of one class" );\r
+ ok( c.has(x, "hi"), "Check has1" );\r
+ ok( c.has(x, "bar"), "Check has2" );\r
+});\r
+\r
+test("remove()", function() {\r
+ $("#ap").children().remove();\r
+ ok( $("#ap").text().length > 10, "Check text is not removed" );\r
+ ok( $("#ap").children().length == 0, "Check remove" );\r
+ \r
+ reset();\r
+ $("#ap").children().remove("a");\r
+ ok( $("#ap").text().length > 10, "Check text is not removed" );\r
+ ok( $("#ap").children().length == 1, "Check filtered remove" );\r
+});\r
+\r
+test("empty()", function() {\r
+ ok( $("#ap").children().empty().text().length == 0, "Check text is removed" );\r
+ ok( $("#ap").children().length == 4, "Check elements are not removed" );\r
+});\r
+\r
+test("eq(), gt(), lt(), contains()", function() {\r
+ ok( $("#ap a").eq(1)[0].id == "groups", "eq()" );\r
+ ok( $("#ap a").gt(1).get(), q("groups", "anchor1", "mark"), "gt()" );\r
+ ok( $("#ap a").lt(2).get(), q("google", "groups", "anchor1"), "lt()" );\r
+ ok( $("#foo a").contains("log").get(), q("anchor2", "simon"), "contains()" );\r
+});
\ No newline at end of file
* @type jQuery
*/
-/**
- * A means of creating a cloned copy of a jQuery object. This function
- * copies the set of matched elements from one jQuery object and creates
- * another, new, jQuery object containing the same elements.
- *
- * @example var div = $("div");
- * $( div ).find("p");
- * @desc Locates all p elements with all div elements, without disrupting the original jQuery object contained in 'div' (as would normally be the case if a simple div.find("p") was done).
- *
- * @name $
- * @param jQuery obj The jQuery object to be cloned.
- * @cat Core
- * @type jQuery
- */
-
jQuery.fn = jQuery.prototype = {
/**
* The current version of jQuery.
for ( var prop in obj )
jQuery.attr(
type ? this.style : this,
- prop, jQuery.prop(this, prop, obj[prop], type)
+ prop, jQuery.prop(this, obj[prop])
);
});
},
return obj;
},
- prop: function(elem, key, value){
+ prop: function(elem, value){
// Handle executable functions
return value.constructor == Function &&
value.call( elem ) || value;
*
* @name appendTo
* @type jQuery
- * @param String expr A jQuery expression of elements to match.
+ * @param <Content> content Content to append to the selected element to.
* @cat DOM/Manipulation
+ * @see append(<Content>)
*/
/**
*
* @name prependTo
* @type jQuery
- * @param String expr A jQuery expression of elements to match.
+ * @param <Content> content Content to prepend to the selected element to.
* @cat DOM/Manipulation
+ * @see prepend(<Content>)
*/
/**
*
* @name insertBefore
* @type jQuery
- * @param String expr A jQuery expression of elements to match.
+ * @param <Content> content Content to insert the selected element before.
* @cat DOM/Manipulation
+ * @see before(<Content>)
*/
/**
*
* @name insertAfter
* @type jQuery
- * @param String expr A jQuery expression of elements to match.
+ * @param <Content> content Content to insert the selected element after.
* @cat DOM/Manipulation
+ * @see after(<Content>)
*/
jQuery.each({
*/
/**
- * Adds the specified class to each of the set of matched elements.
+ * Adds the specified class(es) to each of the set of matched elements.
*
* @example $("p").addClass("selected")
* @before <p>Hello</p>
* @result [ <p class="selected">Hello</p> ]
*
+ * @example $("p").addClass("selected highlight")
+ * @before <p>Hello</p>
+ * @result [ <p class="selected highlight">Hello</p> ]
+ *
* @name addClass
* @type jQuery
- * @param String class A CSS class to add to the elements
+ * @param String class One or more CSS classes to add to the elements
* @cat DOM/Attributes
* @see removeClass(String)
*/
/**
- * Removes all or the specified class from the set of matched elements.
+ * Removes all or the specified class(es) from the set of matched elements.
*
* @example $("p").removeClass()
* @before <p class="selected">Hello</p>
* @before <p class="selected first">Hello</p>
* @result [ <p class="first">Hello</p> ]
*
+ * @example $("p").removeClass("selected highlight")
+ * @before <p class="highlight selected first">Hello</p>
+ * @result [ <p class="first">Hello</p> ]
+ *
* @name removeClass
* @type jQuery
- * @param String class (optional) A CSS class to remove from the elements
+ * @param String class (optional) One or more CSS classes to remove from the elements
* @cat DOM/Attributes
* @see addClass(String)
*/