Thanks for the help.
Here is a streamlined version of my code:
var str1="id=rowid_1"; //string to replace
var str2="id=row_id_1 onclick=alert("hello"); //replace str1 with this
write element_html to oracle database