Saturday, April 24, 2010

jQuery to find and replace HTML content

$(document).ready(function(){

$('body').children().each(function() {
//I wanted to replace localhost\sparky to sparky
//first param of replace is nothing but the regex, you can also use the regex
var loginname= $(this).html().replace(/localhost\\sparky/g,'sparky');

//this replaces the modified HTML
$(this).html(loginname);

//I wanted to remove the time stamp 12.00 AM from date
var time= $(this).html().replace(/12.00 AM/g,' ');


//this replaces the modified HTML
$(this).html(time);
});



});

No comments: