Skip to main content

Bug Tracker

Side navigation

#1797 closed feature (wontfix)

Opened October 12, 2007 12:53AM UTC

Closed October 18, 2007 12:13AM UTC

Integrate extend-like Behavior in each

Reported by: j5 Owned by:
Priority: trivial Milestone: 1.2.2
Component: core Version: 1.2.1
Keywords: each DOM Cc:
Blocked by: Blocking:
Description

Would like each method when passed an object instead of a function to merge the passed object onto the DOM element.

example:

jQuery("#somediv").each({innerHTML: "blah blah blah"});

This would give a shortcut to manipulating non-attribute fields of DOM objects (such as references to other DOM objects which have been attached).

I have modified jQuery-1.2.1.js each as follows to accomplish this:

	// args is for internal usage only
	each: function( obj, fn, args ) {
		if ( args ) {
			if ( obj.length == undefined )
				for ( var i in obj )
					fn.apply( obj[i], args );
			else
				for ( var i = 0, ol = obj.length; i < ol; i++ )
					if ( fn.apply( obj[i], args ) === false ) break;

		// A special, fast, case for the most common use of each
		} else {
			if ( obj.length == undefined )
				// modified to extend each to do an extend on the object returned with object passed
				for ( var i in obj ) {
					if (typeof fn == 'function')
						fn.call( obj[i], i, obj[i] );
					else if (typeof fn == 'object')
						for (var f in fn)
							obj[i][f]=fn[f];
				}
			else
				if (typeof fn == 'function')
					for ( var i = 0, ol = obj.length, val = obj[0]; 
						i < ol && fn.call(val,i,val) !== false; val = obj[++i] ){}
				else if (typeof fn == 'object')
					for ( var i = 0, ol = obj.length; i < ol; i++)
						for (var f in fn)
							obj[i][f]=fn[f];
		}

		return obj;
	},
Attachments (0)
Change History (1)

Changed October 18, 2007 12:13AM UTC by john comment:1

resolution: → wontfix
status: newclosed
type: bugfeature

I don't understand the logic of this addition. Why not just use .attr()?