Okay!
I want to make a function where you can input bascly the body of an html page.
So basicly formatted html. Then I want my function to go through it and add some code to the Open Tags Only (not close tags),
I would like to just have another replace with regex method and replace the html exit tags, however this is a problem as I do not know what the text inside is.
Is there anyway I can do this without making my own custom loop? If so please help! if not, I would apreciate a hand starting off the loop. Thanks
I have made myself a function that does half the work. Only problem is it will do both open and close tags:
Currently if I input
[HTML]
<div id="container" >
<p class="yellow"> text</p>
<a href="#" class="yellow"> link</a>
</div>
[/HTML]
I get:
[HTML]
<div id="container" onclick="select (this)">
<p class="yellow" onclick="select (this)">text</p onclick="select (this)">
<a href="#" class="yellow" onclick="select (this)">link</a onclick="select (this)">
</div onclick="select (this)">
[/HTML]
When I want:
[HTML]
<div id="container" onclick="select (this)">
<p class="yellow" onclick="select (this)">text</p>
<a href="#" class="yellow" onclick="select (this)">link</a>
</div>
[/HTML]
I want to make a function where you can input bascly the body of an html page.
So basicly formatted html. Then I want my function to go through it and add some code to the Open Tags Only (not close tags),
I would like to just have another replace with regex method and replace the html exit tags, however this is a problem as I do not know what the text inside is.
Is there anyway I can do this without making my own custom loop? If so please help! if not, I would apreciate a hand starting off the loop. Thanks
I have made myself a function that does half the work. Only problem is it will do both open and close tags:
Code:
function convert_body(body){
var newbody = body.replace(/[>]/gi, ' onclick="select(this)">');
return newbody;
}
[HTML]
<div id="container" >
<p class="yellow"> text</p>
<a href="#" class="yellow"> link</a>
</div>
[/HTML]
I get:
[HTML]
<div id="container" onclick="select (this)">
<p class="yellow" onclick="select (this)">text</p onclick="select (this)">
<a href="#" class="yellow" onclick="select (this)">link</a onclick="select (this)">
</div onclick="select (this)">
[/HTML]
When I want:
[HTML]
<div id="container" onclick="select (this)">
<p class="yellow" onclick="select (this)">text</p>
<a href="#" class="yellow" onclick="select (this)">link</a>
</div>
[/HTML]
Comment