lo-ga-rie words, lines .. life

$.xhtml

jQuery has a nice feature with which you can get and set the "innerHTML" of a jQuery object. It's not really innerHTML but it does the same. (though firefox will f*ck it up with innerHTML as well.
For once firefox is not behaving as it should. If you enter a simple piece of html like this

<p>this is a paragraph with <br/> 2 lines </p>

Firefox will produce

<p>this is a paragraph with <br> 2 lines </p>

All empty elements will have their trailing / removed.
To fix this i made a really small plugin; which will do just that for you. Let me know if i missed any elements.

jQuery.fn.extend({
xhtml: function( val ) {
	if (val == undefined && jQuery.browser.mozilla)
	{
		//fix tags that don't need closing tags
		string = string.replace(/< (img|input|area|br|hr|param)([^>]*)/igm,'< $1 $2/');
		return string;
	}
	else this.empty().append( val );
}
});

You can use .xhtml just like you normally would use .html
This plugin is a subset of jqxhtml with a small fix in the regexp

Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


No trackbacks yet.

Bad Behavior has blocked 27 access attempts in the last 7 days.