Friday, September 3, 2010

Remove tag without value from html element

Remove tag without value from HTML element and display only value of the Tag.

use the below function to remove the tag from HTML element.

function removeHTMLTags()
{

if(document.getElementById && document.getElementById("input-code"))
{
var strInputCode = document.getElementById("input-code").innerHTML;

/*
This line is optional, it replaces escaped brackets with real ones,
i.e. < is replaced with < and > is replaced with >
*/
strInputCode = strInputCode.replace(/&(lt|gt);/g, function (strMatch, p1){
return (p1 == "lt")? "<" : ">";
});

var strTagStrippedText = strInputCode.replace(/<\/?[^>]+(>|$)/g, "");
alert("Output text:\n" + strTagStrippedText);
// Use the alert below if you want to show the input and the output text
// alert("Input code:\n" + strInputCode + "\n\nOutput text:\n" + strTagStrippedText);
}

}

JQuery live focus and live blur bug fixing code

JQuery focus and blur event does not work with JQuery live event handler.

Here the solution for that. Just add the below code in you JQuery file or your java script file at the end.

and call your event like

$("Element").live("blur", function(){
// Your code goes here...
});

JQuery Blur and Focus code you need to add is here...

/****************************************************
JQUERY BLUR AND FOCUS EVENTS BUG FIXING CODE
****************************************************/

(function(){

var special = jQuery.event.special,
uid1 = 'D' + (+new Date()),
uid2 = 'D' + (+new Date() + 1);

jQuery.event.special.focus = {
setup: function() {
var _self = this,
handler = function(e) {
e = jQuery.event.fix(e);
e.type = 'focus';
if (_self === document) {
jQuery.event.handle.call(_self, e);
}
};

jQuery(this).data(uid1, handler);

if (_self === document) {
/* Must be live() */
if (_self.addEventListener) {
_self.addEventListener('focus', handler, true);
} else {
_self.attachEvent('onfocusin', handler);
}
} else {
return false;
}

},
teardown: function() {
var handler = jQuery(this).data(uid1);
if (this === document) {
if (this.removeEventListener) {
this.removeEventListener('focus', handler, true);
} else {
this.detachEvent('onfocusin', handler);
}
}
}
};

jQuery.event.special.blur = {
setup: function() {
var _self = this,
handler = function(e) {
e = jQuery.event.fix(e);
e.type = 'blur';
if (_self === document) {
jQuery.event.handle.call(_self, e);
}
};

jQuery(this).data(uid2, handler);

if (_self === document) {
/* Must be live() */
if (_self.addEventListener) {
_self.addEventListener('blur', handler, true);
} else {
_self.attachEvent('onfocusout', handler);
}
} else {
return false;
}

},
teardown: function() {
var handler = jQuery(this).data(uid2);
if (this === document) {
if (this.removeEventListener) {
this.removeEventListener('blur', handler, true);
} else {
this.detachEvent('onfocusout', handler);
}
}
}
};

})();


Now Call your blur / focus event

JQuery new features added in JQuery 1.4

Some good new features added in JQuery 1.4
JQuery features