Bug Tracker

Ticket #1024 (closed feature: fixed)

Opened 2 years ago

Last modified 1 week ago

children() and text nodes

Reported by: vmx Assigned to: anonymous
Type: feature Priority: minor
Milestone: 1.2 Component: core
Version: 1.1.4 Keywords:
Cc: Needs: Review

Description (last modified by john) (diff)

It would be nice if children() would also return text nodes. Of course the default behaviour shouldn't be changed. But what about an additional parameter you can set to "true" if you want text nodes to be returned, too. An additional check for every text node would be needed, as phantom nodes shouldn't be return though.

Attachments

Change History

follow-up: ↓ 2   Changed 2 years ago by john

  • need set to Review
  • type changed from enhancement to feature
  • milestone set to 1.1.3

One possible solution:

jQuery.fn.childNodes = function() {
     return this.pushStack( jQuery.map( this, "jQuery.makeArray(a.childNodes)" ) );
};

in reply to: ↑ 1   Changed 2 years ago by jakecigar

Replying to john: Does this really need to be in core? a plugin to deal with those nasty textNodes is more to my liking. this code is still in testing, I will release as a plugin if you like.

jQuery.fn.span = function() {return this.wrap('<span/>').parent()};
jQuery.fn.split = function(re,f) {
	var text=[];
	this.each(function(){
		var tnp = this.parentNode;
		var splits = this.nodeValue.split(re);
		for (var i=0;i<splits.length;i++){
			var t = document.createTextNode(f ? f(splits[i]) : splits[i]);
			tnp.insertBefore(t,this);
			text.push(t);
		};
		tnp.removeChild(this);
	});
	return this.pushStack( text );
};
jQuery.fn.replace  = function(re,f) {
	var text=[], tNodes=false;
	this.each(function(){
		var $this = jQuery(this);
		if (this.nodeType == 3){
			tNodes=true;
			text.push(this.parentNode.insertBefore(document.createTextNode(this.nodeValue.replace(re,f)),this));
			this.parentNode.removeChild(this)
		}else{
			text.push($this.text($this.text().replace(re,f)))
		}
	});
	return this.pushStack(tNodes ? text : this);
};
jQuery.fn.textNodes = function() {
	var text=[];
	this.each(function(){
		var children =this.childNodes;
		for (var i = 0; i < children.length; i++){
			var child = children[i];
			if (child.nodeType == 3) text.push(child);
			}
	})
	return this.pushStack(text);
};

One possible solution: {{{ jQuery.fn.childNodes = function() { return this.pushStack( jQuery.map( this, "jQuery.makeArray(a.childNodes)" ) ); }; }}}

  Changed 2 years ago by jakecigar

I am updating my plugin at http://jqueryjs.googlecode.com/svn/trunk/plugins/textNodes/

it also included John's childNodes

  Changed 2 years ago by john

  • status changed from new to closed
  • version changed from 1.1.2 to 1.1.4
  • resolution set to fixed
  • description changed from It would be nice if children() would also return text nodes. Of course the default behaviour shouldn't be changed. But what about an additional parameter you can set to "true" if you want text nodes to be returned, too. An additional check for every text node would be needed, as phantom nodes shouldn't be return though. to It would be nice if children() would also return text nodes. Of course the default behaviour shouldn't be changed. But what about an additional parameter you can set to "true" if you want text nodes to be returned, too. An additional check for every text node would be needed, as phantom nodes shouldn't be return though.
  • milestone changed from 1.1.3 to 1.2

Fixed in SVN rev [3019].

  Changed 9 months ago by Web Developm

  Changed 4 months ago by aasin

Good coding. Thanks for information.

SSL Certificates * VeriSign SSL * GeoTrust SSL * Thawte SSL * SSL Certificate

  Changed 4 months ago by casininiox

casino online LYRICS Check also: casino online VIDEOS MADONNA Ringtones Send europa casino to your Cell MADONNA Ringtones album:

Note: See TracTickets for help on using tickets.