views:

219

answers:

1

I'm trying to find <body onload="function();"> and replace it with <body> on onClick event.

Any suggestions how this could be done?

Thank you.

UPD. Sorry for an unclear question. Crozin answered my question, I was just trying to remove onload attribute.

+1  A: 

Do you want to search and replace String or DOM Element? If string then use this:

var str = "....<body onliad=\"function();\">....";
var replaced = str.replace("<body onload=\"function();\">", "<body>");

If you want to delete onload attribute from DOM element use this:

document.body.removeAttribute("onload");
Crozin