Bug Tracker

Opened 13 years ago

Closed 13 years ago

Last modified 12 years ago

#1733 closed bug (fixed)

addClass gives error on textnodes

Reported by: achun Owned by:
Priority: major Milestone: 1.2.2
Component: core Version: 1.2.1
Keywords: addClass Cc:
Blocked by: Blocking:

Description

$("<b>addClass</b>\n<b>addClass</b>").addClass('tmp')

error! in className:add fun

		add: function( elem, c ){
			jQuery.each( (c || "").split(/\s+/), function(i, cur){
				if ( !jQuery.className.has( elem.className, cur ) )
					elem.className += ( elem.className ? " " : "" ) + cur;
			});
		},

fix?

		add: function( elem, c ){
			jQuery.each( (c || "").split(/\s+/), function(i, cur){
				if ( !jQuery.className.has( elem.className||"", cur ) )
					elem.className += ( elem.className ? " " : "" ) + cur;
			});
		},

Attachments (1)

1733.diff (2.5 KB) - added by brandon 13 years ago.
Patch + Tests for text nodes in jQuery.className methods

Download all attachments as: .zip

Change History (8)

Changed 13 years ago by brandon

Attachment: 1733.diff added

Patch + Tests for text nodes in jQuery.className methods

comment:1 Changed 13 years ago by brandon

need: ReviewCommit

I've attached patch + tests to make jQuery.className.remove/add/has not fail when it gets a non element node.

However, I'm wondering if the better solution (or in addition to) should be that text nodes do not make it into the jQuery collection via jQuery.clean.

comment:2 Changed 13 years ago by davidserduke

I don't think we can keep text nodes out of the jQuery collection. I looked in to that recently and realized there are several ways to get text nodes in. In fact, the function .contents() specifically includes text nodes.

http://docs.jquery.com/Traversing/contents

With that said, do you think it makes sense to implement the patch? It looks like a good solution to me.

comment:3 in reply to:  2 Changed 13 years ago by brandon

Replying to davidserduke:

Yeah we definitely can't keep text nodes out now ... however we need to be mindful of this in our manipulation methods such as css, attr and the class methods. We should probably go ahead and be proactive and test/patch the other manipulation methods.

comment:4 Changed 13 years ago by davidserduke

Summary: addClass?addClass fails on textnodes

comment:5 Changed 13 years ago by davidserduke

Summary: addClass fails on textnodesaddClass gives error on textnodes

comment:6 Changed 13 years ago by davidserduke

See #1039 for a similar ticket.

comment:7 Changed 13 years ago by davidserduke

Resolution: fixed
Status: newclosed

Fixed in [4062] taking Brandon's suggestion that text nodes should not break jQuery even when they are in the jQuery object. addClass was fixed along with the other functions in the API.

Note: See TracTickets for help on using tickets.