I am trying to change the HTML tag and remove the class/style attributes after the tag. I already know how to do this if I create the code before hand and replace, now I want to know how to find the tags on an already loaded page and replace them with my js.
var s = "<h2 class=\"title\" style=\"font-color: red;\">Blog Post</h2>";
s = s.replace("<h2 class=\"title\" style=\"font-color: red;\">","<p>");
s = s.replace(/<\/h2>/g, "</p>");
Start with
<h2 class="title" style="font-color: red;">Blog Post</h2>
End with
<p>Blog Post</p>
So the question is how can I create the var s
with existing HTML?
How do I find h2.title
on a page and give it to var s
?
edit I have no javascript experience except for this script which I found and tweaked. Please explain how I can grab text from an existing document, and make it my var for s.replace to manipulate.
Blog Post
` to `Blog Post
` – Ruan Mendes Nov 28 '12 at 00:42blog post 1
` and then run `s.replace`. – Nov 28 '12 at 00:50blog post 1
and then run s.replace` But two things are for sure: your regexp is going to be very brittle; also you can't just expect a call to `String.replace()` to update the DOM, you'd have to set the `innerHTML` of a parent node (assuming it was the only child) – Ruan Mendes Nov 28 '12 at 00:54