Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replace function

Status
Not open for further replies.

chebbi

Programmer
Feb 6, 2002
98
IN
Hi All

How do u replace a string with a html tag?i need to replace a part of innerHTML text with a font tag. For example if i need to replace text inside a table cell(plain cell with only text in it) by grabbing its value using innerHTML property how do i replace say first 3 characters with a font tag using a replace function? Badrinath Chebbi
 
I don't see that you would need to use the replace function. You could do this to replace the first three characters and add your font tag:
<table><tr>
<td id=cell>123MyText</td>
</tr></table>
<script>
var td=document.body.getElementsByID(&quot;cell&quot;);
td.innerHTML=&quot;<font color=red>&quot;+td.innerHTML.substring(3)+&quot;</font>&quot;;
</script>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top