Is it possible in CSS to make all of a piece of text on a page be replaced by some other text, say, for instance that in my HTML I put "NNN" on the page it could be replaced by "MMM"? Can I do that? Thanks.YOu can use innerHTML to do that
<div id="div1">Hello World</div>
<a href=http://www.webdeveloper.com/forum/archive/index.php/"#null" onclick="document.getElementById('div1').innerHTML='Hi There' ">Click me</a>It can be done with JavaScript and regex, but not CSS. Here's how with JavaScript:
<script type="text/javascript">
onload = function() {
str = document.getElementsByTagName("body")[0];
newstr = str.innerHTML.replace(/foo/g, "bar");
str.innerHTML = newstr;
}
</script>To let you know of its existence, there is CSS that allows you to insert content before or after elements, but not replace text. It is CSS2 (<!-- w --><a class="postlink" href="http://www.w3.org/TR/CSS2/">www.w3.org/TR/CSS2/</a><!-- w -->) and not supported in any browser that I'm aware of, as of yet...
p:before { /* Insert an asterisk at the beginning of every <p> tag */
content("*");
}
p:after { /* Insert a tilde at the end of every </p> tag */
content("~");
}
You can also set up CSS as a counter to make paragraphs become counted, and even set them up to act as lists, in some cases.
[J]onaOriginally posted by pyro
It can be done with JavaScript and regex, but not CSS. Here's how with JavaScript...
A little reminder here, if you are using an XHTML DTD, it is considered invalid JavaScript code to use innerHTML. For HTML 4.01, however, this is apparently considered "okay."
[J]onaThanks pyro, I used your methos and it worked great! But also, thanks to everyone for trying to help. Could I use the following code to place it on every page?
<style><!--
/head:before {
content("<script type="text/javascript">
onload = function() {
str = document.getElementsByTagName("body")[0];
newstr = str.innerHTML.replace(/foo/g, "bar");
str.innerHTML = newstr;
}
</script>");
}
--></style>No, but you could use an external JavaScript file:
Insert the code I gave you (minus the opening and closing <script> tags) into a file with a .js extention, and add this to the <head> of you page.
<script type="text/javascript" src=http://www.webdeveloper.com/forum/archive/index.php/"script.js"></script>thanksSure thing...
<div id="div1">Hello World</div>
<a href=http://www.webdeveloper.com/forum/archive/index.php/"#null" onclick="document.getElementById('div1').innerHTML='Hi There' ">Click me</a>It can be done with JavaScript and regex, but not CSS. Here's how with JavaScript:
<script type="text/javascript">
onload = function() {
str = document.getElementsByTagName("body")[0];
newstr = str.innerHTML.replace(/foo/g, "bar");
str.innerHTML = newstr;
}
</script>To let you know of its existence, there is CSS that allows you to insert content before or after elements, but not replace text. It is CSS2 (<!-- w --><a class="postlink" href="http://www.w3.org/TR/CSS2/">www.w3.org/TR/CSS2/</a><!-- w -->) and not supported in any browser that I'm aware of, as of yet...
p:before { /* Insert an asterisk at the beginning of every <p> tag */
content("*");
}
p:after { /* Insert a tilde at the end of every </p> tag */
content("~");
}
You can also set up CSS as a counter to make paragraphs become counted, and even set them up to act as lists, in some cases.
[J]onaOriginally posted by pyro
It can be done with JavaScript and regex, but not CSS. Here's how with JavaScript...
A little reminder here, if you are using an XHTML DTD, it is considered invalid JavaScript code to use innerHTML. For HTML 4.01, however, this is apparently considered "okay."
[J]onaThanks pyro, I used your methos and it worked great! But also, thanks to everyone for trying to help. Could I use the following code to place it on every page?
<style><!--
/head:before {
content("<script type="text/javascript">
onload = function() {
str = document.getElementsByTagName("body")[0];
newstr = str.innerHTML.replace(/foo/g, "bar");
str.innerHTML = newstr;
}
</script>");
}
--></style>No, but you could use an external JavaScript file:
Insert the code I gave you (minus the opening and closing <script> tags) into a file with a .js extention, and add this to the <head> of you page.
<script type="text/javascript" src=http://www.webdeveloper.com/forum/archive/index.php/"script.js"></script>thanksSure thing...