Reputation: 182
I have a online webpage. There has a code placed by default:-
<body><center><table border="0" width="100%"><tr><td valign="top" align="center"><div class="webpage_body" style="text-align: left;">
I am facing many issues with this code. It is placed after </head>
tag. I want to disable or replace it via JavaScript or CSS.
I've tried to replace it into an unknown HTML by javascript:-
var s="<center><table border="0" width="100%"><tr><td valign="top" align="center"><div class="webpage_body" style="text-align: left;">"; s = s.replace(/<center>/g, "<c>"); s = s.replace(/<table>/g,"<ta>"); s = s.replace(/<tr>/g,"<fr>"); alert(s);
But nothing happens to it. (Edit:) Also I can't replace the <table
because it isn't <table>
! How can I do this?
Upvotes: 1
Views: 104
Reputation: 2965
You've got a typo in there. You're using "
for the HTML
string but inside of the HTML
, you use "
too. That will break it. Just try to use '
at the beginning and the end of the string.
This is how it looks if you are using a editor:
This if how it looks if you are wrap it with '
instead of "
The Boxes are there to visualize the strings.
Here's the working example:
var s = '<center><table border="0" width="100%"><tr><td valign="top" align="center"><div class="webpage_body" style="text-align: left;">';
s = s.replace(/<center>/g, "<c>");
s = s.replace(/<table>/g, "<ta>");
s = s.replace(/<tr>/g, "<fr>");
alert(s);
Just a little hint: In your example, <table>
will never be replaced because your example has no <table>
. Only <table
.
You can do this with s.replace(/<table/g, "<ta");
or s.replace(/table/g, "ta");
.
Upvotes: 2