3 var bareObj = function(value) { return value; };
4 var functionReturningObj = function(value) { return (function() { return value; }); };
6 test("attr(String)", function() {
9 // This one sometimes fails randomly ?!
10 equals( jQuery('#text1').attr('value'), "Test", 'Check for value attribute' );
12 equals( jQuery('#text1').attr('value', "Test2").attr('defaultValue'), "Test", 'Check for defaultValue attribute' );
13 equals( jQuery('#text1').attr('type'), "text", 'Check for type attribute' );
14 equals( jQuery('#radio1').attr('type'), "radio", 'Check for type attribute' );
15 equals( jQuery('#check1').attr('type'), "checkbox", 'Check for type attribute' );
16 equals( jQuery('#simon1').attr('rel'), "bookmark", 'Check for rel attribute' );
17 equals( jQuery('#google').attr('title'), "Google!", 'Check for title attribute' );
18 equals( jQuery('#mark').attr('hreflang'), "en", 'Check for hreflang attribute' );
19 equals( jQuery('#en').attr('lang'), "en", 'Check for lang attribute' );
20 equals( jQuery('#simon').attr('class'), "blog link", 'Check for class attribute' );
21 equals( jQuery('#name').attr('name'), "name", 'Check for name attribute' );
22 equals( jQuery('#text1').attr('name'), "action", 'Check for name attribute' );
23 ok( jQuery('#form').attr('action').indexOf("formaction") >= 0, 'Check for action attribute' );
24 // Temporarily disabled. See: #4299
25 // ok( jQuery('#form').attr('action','newformaction').attr('action').indexOf("newformaction") >= 0, 'Check that action attribute was changed' );
26 equals( jQuery('#text1').attr('maxlength'), '30', 'Check for maxlength attribute' );
27 equals( jQuery('#text1').attr('maxLength'), '30', 'Check for maxLength attribute' );
28 equals( jQuery('#area1').attr('maxLength'), '30', 'Check for maxLength attribute' );
29 equals( jQuery('#select2').attr('selectedIndex'), 3, 'Check for selectedIndex attribute' );
30 equals( jQuery('#foo').attr('nodeName').toUpperCase(), 'DIV', 'Check for nodeName attribute' );
31 equals( jQuery('#foo').attr('tagName').toUpperCase(), 'DIV', 'Check for tagName attribute' );
33 // using innerHTML in IE causes href attribute to be serialized to the full path
34 jQuery('<a/>').attr({ 'id': 'tAnchor5', 'href': '#5' }).appendTo('#main');
35 equals( jQuery('#tAnchor5').attr('href'), "#5", 'Check for non-absolute href (an anchor)' );
37 equals( jQuery("<option/>").attr("selected"), false, "Check selected attribute on disconnected element." );
40 // Related to [5574] and [5683]
41 var body = document.body, $body = jQuery(body);
43 ok( $body.attr('foo') === undefined, 'Make sure that a non existent attribute returns undefined' );
44 ok( $body.attr('nextSibling') === null, 'Make sure a null expando returns null' );
46 body.setAttribute('foo', 'baz');
47 equals( $body.attr('foo'), 'baz', 'Make sure the dom attribute is retrieved when no expando is found' );
50 equals( $body.attr('foo'), 'bar', 'Make sure the expando is preferred over the dom attribute' );
52 $body.attr('foo','cool');
53 equals( $body.attr('foo'), 'cool', 'Make sure that setting works well when both expando and dom attribute are available' );
56 ok( $body.attr('foo') === undefined, 'Make sure the expando is preferred over the dom attribute, even if undefined' );
58 body.removeAttribute('foo'); // Cleanup
60 var select = document.createElement("select"), optgroup = document.createElement("optgroup"), option = document.createElement("option");
61 optgroup.appendChild( option );
62 select.appendChild( optgroup );
64 equals( jQuery(option).attr("selected"), true, "Make sure that a single option is selected, even when in an optgroup." );
66 ok( jQuery("<div/>").attr("doesntexist") === undefined, "Make sure undefined is returned when no attribute is found." );
67 ok( jQuery().attr("doesntexist") === undefined, "Make sure undefined is returned when no element is there." );
71 test("attr(String) in XML Files", function() {
74 jQuery.get("data/dashboard.xml", function(xml) {
75 equals( jQuery("locations", xml).attr("class"), "foo", "Check class attribute in XML document" );
76 equals( jQuery("location", xml).attr("for"), "bar", "Check for attribute in XML document" );
82 test("attr(String, Function)", function() {
84 equals( jQuery('#text1').attr('value', function() { return this.id ;})[0].value, "text1", "Set value from id" );
85 equals( jQuery('#text1').attr('title', function(i) { return i }).attr('title'), "0", "Set value with an index");
88 test("attr(Hash)", function() {
91 jQuery("div").attr({foo: 'baz', zoo: 'ping'}).each(function(){
92 if ( this.getAttribute('foo') != "baz" && this.getAttribute('zoo') != "ping" ) pass = false;
94 ok( pass, "Set Multiple Attributes" );
95 equals( jQuery('#text1').attr({'value': function() { return this.id; }})[0].value, "text1", "Set attribute to computed value #1" );
96 equals( jQuery('#text1').attr({'title': function(i) { return i; }}).attr('title'), "0", "Set attribute to computed value #2");
100 test("attr(String, Object)", function() {
102 var div = jQuery("div").attr("foo", "bar"),
104 for ( var i = 0; i < div.size(); i++ ) {
105 if ( div.get(i).getAttribute('foo') != "bar" ){
110 equals( fail, false, "Set Attribute, the #"+fail+" element didn't get the attribute 'foo'" );
112 // Fails on IE since recent changes to .attr()
113 // ok( jQuery("#foo").attr({"width": null}), "Try to set an attribute to nothing" );
115 jQuery("#name").attr('name', 'something');
116 equals( jQuery("#name").attr('name'), 'something', 'Set name attribute' );
117 jQuery("#check2").attr('checked', true);
118 equals( document.getElementById('check2').checked, true, 'Set checked attribute' );
119 jQuery("#check2").attr('checked', false);
120 equals( document.getElementById('check2').checked, false, 'Set checked attribute' );
121 jQuery("#text1").attr('readonly', true);
122 equals( document.getElementById('text1').readOnly, true, 'Set readonly attribute' );
123 jQuery("#text1").attr('readonly', false);
124 equals( document.getElementById('text1').readOnly, false, 'Set readonly attribute' );
125 jQuery("#name").attr('maxlength', '5');
126 equals( document.getElementById('name').maxLength, '5', 'Set maxlength attribute' );
127 jQuery("#name").attr('maxLength', '10');
128 equals( document.getElementById('name').maxLength, '10', 'Set maxlength attribute' );
130 var table = jQuery('#table').append("<tr><td>cell</td></tr><tr><td>cell</td><td>cell</td></tr><tr><td>cell</td><td>cell</td></tr>"),
131 td = table.find('td:first');
132 td.attr("rowspan", "2");
133 equals( td[0].rowSpan, 2, "Check rowspan is correctly set" );
134 td.attr("colspan", "2");
135 equals( td[0].colSpan, 2, "Check colspan is correctly set" );
136 table.attr("cellspacing", "2");
137 equals( table[0].cellSpacing, 2, "Check cellspacing is correctly set" );
140 jQuery("#name").attr('someAttr', '0');
141 equals( jQuery("#name").attr('someAttr'), '0', 'Set attribute to a string of "0"' );
142 jQuery("#name").attr('someAttr', 0);
143 equals( jQuery("#name").attr('someAttr'), 0, 'Set attribute to the number 0' );
144 jQuery("#name").attr('someAttr', 1);
145 equals( jQuery("#name").attr('someAttr'), 1, 'Set attribute to the number 1' );
147 // using contents will get comments regular, text, and comment nodes
148 var j = jQuery("#nonnodes").contents();
150 j.attr("name", "attrvalue");
151 equals( j.attr("name"), "attrvalue", "Check node,textnode,comment for attr" );
152 j.removeAttr("name");
156 var type = jQuery("#check2").attr('type');
159 jQuery("#check2").attr('type','hidden');
163 ok( thrown, "Exception thrown when trying to change type property" );
164 equals( type, jQuery("#check2").attr('type'), "Verify that you can't change the type of an input element" );
166 var check = document.createElement("input");
169 jQuery(check).attr('type','checkbox');
173 ok( thrown, "Exception thrown when trying to change type property" );
174 equals( "checkbox", jQuery(check).attr('type'), "Verify that you can change the type of an input element that isn't in the DOM" );
176 var check = jQuery("<input />");
179 check.attr('type','checkbox');
183 ok( thrown, "Exception thrown when trying to change type property" );
184 equals( "checkbox", check.attr('type'), "Verify that you can change the type of an input element that isn't in the DOM" );
186 var button = jQuery("#button");
189 button.attr('type','submit');
193 ok( thrown, "Exception thrown when trying to change type property" );
194 equals( "button", button.attr('type'), "Verify that you can't change the type of a button element" );
197 test("attr(jquery_method)", function(){
200 var $elem = jQuery("<div />"),
204 $elem.attr({'html': 'foo'}, true);
205 equals( elem.innerHTML, 'foo', 'attr(html)');
207 $elem.attr({'text': 'bar'}, true);
208 equals( elem.innerHTML, 'bar', 'attr(text)');
210 $elem.attr({'css': {color:'red'}}, true);
211 ok( /^(#ff0000|red)$/i.test(elem.style.color), 'attr(css)');
213 $elem.attr({'height': 10}, true);
214 equals( elem.style.height, '10px', 'attr(height)');
216 // Multiple attributes
220 css:{ paddingLeft:1, paddingRight:1 }
223 equals( elem.style.width, '10px', 'attr({...})');
224 equals( elem.style.paddingLeft, '1px', 'attr({...})');
225 equals( elem.style.paddingRight, '1px', 'attr({...})');
229 test("attr(String, Object) - Loaded via XML document", function() {
232 jQuery.get('data/dashboard.xml', function(xml) {
234 jQuery('tab', xml).each(function() {
235 titles.push(jQuery(this).attr('title'));
237 equals( titles[0], 'Location', 'attr() in XML context: Check first title' );
238 equals( titles[1], 'Users', 'attr() in XML context: Check second title' );
244 test("attr('tabindex')", function() {
247 // elements not natively tabbable
248 equals(jQuery('#listWithTabIndex').attr('tabindex'), 5, 'not natively tabbable, with tabindex set to 0');
249 equals(jQuery('#divWithNoTabIndex').attr('tabindex'), undefined, 'not natively tabbable, no tabindex set');
252 equals(jQuery('#linkWithNoTabIndex').attr('tabindex'), 0, 'anchor with href, no tabindex set');
253 equals(jQuery('#linkWithTabIndex').attr('tabindex'), 2, 'anchor with href, tabindex set to 2');
254 equals(jQuery('#linkWithNegativeTabIndex').attr('tabindex'), -1, 'anchor with href, tabindex set to -1');
256 // anchor without href
257 equals(jQuery('#linkWithNoHrefWithNoTabIndex').attr('tabindex'), undefined, 'anchor without href, no tabindex set');
258 equals(jQuery('#linkWithNoHrefWithTabIndex').attr('tabindex'), 1, 'anchor without href, tabindex set to 2');
259 equals(jQuery('#linkWithNoHrefWithNegativeTabIndex').attr('tabindex'), -1, 'anchor without href, no tabindex set');
262 test("attr('tabindex', value)", function() {
265 var element = jQuery('#divWithNoTabIndex');
266 equals(element.attr('tabindex'), undefined, 'start with no tabindex');
268 // set a positive string
269 element.attr('tabindex', '1');
270 equals(element.attr('tabindex'), 1, 'set tabindex to 1 (string)');
273 element.attr('tabindex', '0');
274 equals(element.attr('tabindex'), 0, 'set tabindex to 0 (string)');
276 // set a negative string
277 element.attr('tabindex', '-1');
278 equals(element.attr('tabindex'), -1, 'set tabindex to -1 (string)');
280 // set a positive number
281 element.attr('tabindex', 1);
282 equals(element.attr('tabindex'), 1, 'set tabindex to 1 (number)');
285 element.attr('tabindex', 0);
286 equals(element.attr('tabindex'), 0, 'set tabindex to 0 (number)');
288 // set a negative number
289 element.attr('tabindex', -1);
290 equals(element.attr('tabindex'), -1, 'set tabindex to -1 (number)');
292 element = jQuery('#linkWithTabIndex');
293 equals(element.attr('tabindex'), 2, 'start with tabindex 2');
295 element.attr('tabindex', -1);
296 equals(element.attr('tabindex'), -1, 'set negative tabindex');
299 test("removeAttr(String)", function() {
301 equals( jQuery('#mark').removeAttr( "class" )[0].className, "", "remove class" );
304 test("val()", function() {
307 document.getElementById('text1').value = "bla";
308 equals( jQuery("#text1").val(), "bla", "Check for modified value of input element" );
312 equals( jQuery("#text1").val(), "Test", "Check for value of input element" );
313 // ticket #1714 this caused a JS error in IE
314 equals( jQuery("#first").val(), "", "Check a paragraph element to see if it has a value" );
315 ok( jQuery([]).val() === undefined, "Check an empty jQuery object will return undefined from val" );
317 equals( jQuery('#select2').val(), '3', 'Call val() on a single="single" select' );
319 same( jQuery('#select3').val(), ['1', '2'], 'Call val() on a multiple="multiple" select' );
321 equals( jQuery('#option3c').val(), '2', 'Call val() on a option element with value' );
323 equals( jQuery('#option3a').val(), '', 'Call val() on a option element with empty value' );
325 equals( jQuery('#option3e').val(), 'no value', 'Call val() on a option element with no value attribute' );
327 equals( jQuery('#option3a').val(), '', 'Call val() on a option element with no value attribute' );
329 jQuery('#select3').val("");
330 same( jQuery('#select3').val(), [''], 'Call val() on a multiple="multiple" select' );
332 same( jQuery('#select4').val(), [], 'Call val() on multiple="multiple" select with all disabled options' );
334 jQuery('#select4 optgroup').add('#select4 > [disabled]').attr('disabled', false);
335 same( jQuery('#select4').val(), ['2', '3'], 'Call val() on multiple="multiple" select with some disabled options' );
337 jQuery('#select4').attr('disabled', true);
338 same( jQuery('#select4').val(), ['2', '3'], 'Call val() on disabled multiple="multiple" select' );
340 var checks = jQuery("<input type='checkbox' name='test' value='1'/><input type='checkbox' name='test' value='2'/><input type='checkbox' name='test' value=''/><input type='checkbox' name='test'/>").appendTo("#form");
342 same( checks.serialize(), "", "Get unchecked values." );
344 equals( checks.eq(3).val(), "on", "Make sure a value of 'on' is provided if none is specified." );
347 same( checks.serialize(), "test=2", "Get a single checked value." );
349 checks.val([ "1", "" ]);
350 same( checks.serialize(), "test=1&test=", "Get multiple checked values." );
352 checks.val([ "", "2" ]);
353 same( checks.serialize(), "test=2&test=", "Get multiple checked values." );
355 checks.val([ "1", "on" ]);
356 same( checks.serialize(), "test=1&test=on", "Get multiple checked values." );
361 var testVal = function(valueObj) {
364 jQuery("#text1").val(valueObj( 'test' ));
365 equals( document.getElementById('text1').value, "test", "Check for modified (via val(String)) value of input element" );
367 jQuery("#text1").val(valueObj( 67 ));
368 equals( document.getElementById('text1').value, "67", "Check for modified (via val(Number)) value of input element" );
370 jQuery("#select1").val(valueObj( "3" ));
371 equals( jQuery("#select1").val(), "3", "Check for modified (via val(String)) value of select element" );
373 jQuery("#select1").val(valueObj( 2 ));
374 equals( jQuery("#select1").val(), "2", "Check for modified (via val(Number)) value of select element" );
376 jQuery("#select1").append("<option value='4'>four</option>");
377 jQuery("#select1").val(valueObj( 4 ));
378 equals( jQuery("#select1").val(), "4", "Should be possible to set the val() to a newly created option" );
380 // using contents will get comments regular, text, and comment nodes
381 var j = jQuery("#nonnodes").contents();
382 j.val(valueObj( "asdf" ));
383 equals( j.val(), "asdf", "Check node,textnode,comment with val()" );
384 j.removeAttr("value");
387 test("val(String/Number)", function() {
391 test("val(Function)", function() {
392 testVal(functionReturningObj);
395 test("val(Function) with incoming value", function() {
398 var oldVal = jQuery("#text1").val();
400 jQuery("#text1").val(function(i, val) {
401 equals( val, oldVal, "Make sure the incoming value is correct." );
405 equals( document.getElementById('text1').value, "test", "Check for modified (via val(String)) value of input element" );
407 oldVal = jQuery("#text1").val();
409 jQuery("#text1").val(function(i, val) {
410 equals( val, oldVal, "Make sure the incoming value is correct." );
414 equals( document.getElementById('text1').value, "67", "Check for modified (via val(Number)) value of input element" );
416 oldVal = jQuery("#select1").val();
418 jQuery("#select1").val(function(i, val) {
419 equals( val, oldVal, "Make sure the incoming value is correct." );
423 equals( jQuery("#select1").val(), "3", "Check for modified (via val(String)) value of select element" );
425 oldVal = jQuery("#select1").val();
427 jQuery("#select1").val(function(i, val) {
428 equals( val, oldVal, "Make sure the incoming value is correct." );
432 equals( jQuery("#select1").val(), "2", "Check for modified (via val(Number)) value of select element" );
434 jQuery("#select1").append("<option value='4'>four</option>");
436 oldVal = jQuery("#select1").val();
438 jQuery("#select1").val(function(i, val) {
439 equals( val, oldVal, "Make sure the incoming value is correct." );
443 equals( jQuery("#select1").val(), "4", "Should be possible to set the val() to a newly created option" );
446 var testAddClass = function(valueObj) {
448 var div = jQuery("div");
449 div.addClass( valueObj("test") );
451 for ( var i = 0; i < div.size(); i++ ) {
452 if ( div.get(i).className.indexOf("test") == -1 ) pass = false;
454 ok( pass, "Add Class" );
456 // using contents will get regular, text, and comment nodes
457 var j = jQuery("#nonnodes").contents();
458 j.addClass( valueObj("asdf") );
459 ok( j.hasClass("asdf"), "Check node,textnode,comment for addClass" );
461 div = jQuery("<div/>");
463 div.addClass( valueObj("test") );
464 equals( div.attr("class"), "test", "Make sure there's no extra whitespace." );
466 div.attr("class", " foo");
467 div.addClass( valueObj("test") );
468 equals( div.attr("class"), "foo test", "Make sure there's no extra whitespace." );
470 div.attr("class", "foo");
471 div.addClass( valueObj("bar baz") );
472 equals( div.attr("class"), "foo bar baz", "Make sure there isn't too much trimming." );
475 test("addClass(String)", function() {
476 testAddClass(bareObj);
479 test("addClass(Function)", function() {
480 testAddClass(functionReturningObj);
483 test("addClass(Function) with incoming value", function() {
486 var div = jQuery("div"), old = div.map(function(){
487 return jQuery(this).attr("class");
490 div.addClass(function(i, val) {
491 if ( this.id !== "_firebugConsole" ) {
492 equals( val, old[i], "Make sure the incoming value is correct." );
498 for ( var i = 0; i < div.size(); i++ ) {
499 if ( div.get(i).className.indexOf("test") == -1 ) pass = false;
501 ok( pass, "Add Class" );
504 var testRemoveClass = function(valueObj) {
507 var $divs = jQuery('div');
509 $divs.addClass("test").removeClass( valueObj("test") );
511 ok( !$divs.is('.test'), "Remove Class" );
514 $divs = jQuery('div');
516 $divs.addClass("test").addClass("foo").addClass("bar");
517 $divs.removeClass( valueObj("test") ).removeClass( valueObj("bar") ).removeClass( valueObj("foo") );
519 ok( !$divs.is('.test,.bar,.foo'), "Remove multiple classes" );
522 $divs = jQuery('div');
524 // Make sure that a null value doesn't cause problems
525 $divs.eq(0).addClass("test").removeClass( valueObj(null) );
526 ok( $divs.eq(0).is('.test'), "Null value passed to removeClass" );
528 $divs.eq(0).addClass("test").removeClass( valueObj("") );
529 ok( $divs.eq(0).is('.test'), "Empty string passed to removeClass" );
531 // using contents will get regular, text, and comment nodes
532 var j = jQuery("#nonnodes").contents();
533 j.removeClass( valueObj("asdf") );
534 ok( !j.hasClass("asdf"), "Check node,textnode,comment for removeClass" );
536 var div = document.createElement("div");
537 div.className = " test foo ";
539 jQuery(div).removeClass( valueObj("foo") );
540 equals( div.className, "test", "Make sure remaining className is trimmed." );
542 div.className = " test ";
544 jQuery(div).removeClass( valueObj("test") );
545 equals( div.className, "", "Make sure there is nothing left after everything is removed." );
548 test("removeClass(String) - simple", function() {
549 testRemoveClass(bareObj);
552 test("removeClass(Function) - simple", function() {
553 testRemoveClass(functionReturningObj);
556 test("removeClass(Function) with incoming value", function() {
559 var $divs = jQuery('div').addClass("test"), old = $divs.map(function(){
560 return jQuery(this).attr("class");
563 $divs.removeClass(function(i, val) {
564 if ( this.id !== "_firebugConsole" ) {
565 equals( val, old[i], "Make sure the incoming value is correct." );
570 ok( !$divs.is('.test'), "Remove Class" );
575 var testToggleClass = function(valueObj) {
578 var e = jQuery("#firstp");
579 ok( !e.is(".test"), "Assert class not present" );
580 e.toggleClass( valueObj("test") );
581 ok( e.is(".test"), "Assert class present" );
582 e.toggleClass( valueObj("test") );
583 ok( !e.is(".test"), "Assert class not present" );
585 // class name with a boolean
586 e.toggleClass( valueObj("test"), false );
587 ok( !e.is(".test"), "Assert class not present" );
588 e.toggleClass( valueObj("test"), true );
589 ok( e.is(".test"), "Assert class present" );
590 e.toggleClass( valueObj("test"), false );
591 ok( !e.is(".test"), "Assert class not present" );
593 // multiple class names
594 e.addClass("testA testB");
595 ok( (e.is(".testA.testB")), "Assert 2 different classes present" );
596 e.toggleClass( valueObj("testB testC") );
597 ok( (e.is(".testA.testC") && !e.is(".testB")), "Assert 1 class added, 1 class removed, and 1 class kept" );
598 e.toggleClass( valueObj("testA testC") );
599 ok( (!e.is(".testA") && !e.is(".testB") && !e.is(".testC")), "Assert no class present" );
601 // toggleClass storage
603 ok( e.get(0).className === "", "Assert class is empty (data was empty)" );
604 e.addClass("testD testE");
605 ok( e.is(".testD.testE"), "Assert class present" );
607 ok( !e.is(".testD.testE"), "Assert class not present" );
608 ok( e.data('__className__') === 'testD testE', "Assert data was stored" );
610 ok( e.is(".testD.testE"), "Assert class present (restored from data)" );
611 e.toggleClass(false);
612 ok( !e.is(".testD.testE"), "Assert class not present" );
614 ok( e.is(".testD.testE"), "Assert class present (restored from data)" );
616 e.toggleClass(false);
618 ok( e.is(".testD.testE"), "Assert class present (restored from data)" );
623 e.removeClass("testD");
624 e.removeData('__className__');
627 test("toggleClass(String|boolean|undefined[, boolean])", function() {
628 testToggleClass(bareObj);
631 test("toggleClass(Function[, boolean])", function() {
632 testToggleClass(functionReturningObj);
635 test("toggleClass(Fucntion[, boolean]) with incoming value", function() {
638 var e = jQuery("#firstp"), old = e.attr("class");
639 ok( !e.is(".test"), "Assert class not present" );
641 e.toggleClass(function(i, val) {
642 equals( val, old, "Make sure the incoming value is correct." );
645 ok( e.is(".test"), "Assert class present" );
647 old = e.attr("class");
649 e.toggleClass(function(i, val) {
650 equals( val, old, "Make sure the incoming value is correct." );
653 ok( !e.is(".test"), "Assert class not present" );
655 old = e.attr("class");
657 // class name with a boolean
658 e.toggleClass(function(i, val, state) {
659 equals( val, old, "Make sure the incoming value is correct." );
660 equals( state, false, "Make sure that the state is passed in." );
663 ok( !e.is(".test"), "Assert class not present" );
665 old = e.attr("class");
667 e.toggleClass(function(i, val, state) {
668 equals( val, old, "Make sure the incoming value is correct." );
669 equals( state, true, "Make sure that the state is passed in." );
672 ok( e.is(".test"), "Assert class present" );
674 old = e.attr("class");
676 e.toggleClass(function(i, val, state) {
677 equals( val, old, "Make sure the incoming value is correct." );
678 equals( state, false, "Make sure that the state is passed in." );
681 ok( !e.is(".test"), "Assert class not present" );
684 e.removeClass("test");
685 e.removeData('__className__');
688 test("addClass, removeClass, hasClass", function() {
691 var jq = jQuery("<p>Hi</p>"), x = jq[0];
694 equals( x.className, "hi", "Check single added class" );
696 jq.addClass("foo bar");
697 equals( x.className, "hi foo bar", "Check more added classes" );
700 equals( x.className, "", "Remove all classes" );
702 jq.addClass("hi foo bar");
703 jq.removeClass("foo");
704 equals( x.className, "hi bar", "Check removal of one class" );
706 ok( jq.hasClass("hi"), "Check has1" );
707 ok( jq.hasClass("bar"), "Check has2" );
709 var jq = jQuery("<p class='class1\nclass2\tcla.ss3\n'></p>");
710 ok( jq.hasClass("class1"), "Check hasClass with carriage return" );
711 ok( jq.is(".class1"), "Check is with carriage return" );
712 ok( jq.hasClass("class2"), "Check hasClass with tab" );
713 ok( jq.is(".class2"), "Check is with tab" );
714 ok( jq.hasClass("cla.ss3"), "Check hasClass with dot" );
716 jq.removeClass("class2");
717 ok( jq.hasClass("class2")==false, "Check the class has been properly removed" );
718 jq.removeClass("cla");
719 ok( jq.hasClass("cla.ss3"), "Check the dotted class has not been removed" );
720 jq.removeClass("cla.ss3");
721 ok( jq.hasClass("cla.ss3")==false, "Check the dotted class has been removed" );