Want to strikethrough a text

P

Prof

I am just learning javascript, and i wanted to strike a text in a
normal <p> tag using javascript.
I have tried to use a old script found in th forums , it works ,
although it uses the <a> tag and hence has a underline. I wanted to
find a script in which i can check a checkbox and the text nearby will
get striked automatically.

Can anyone help here please. Or suggest what i should use. Cause i am
not getting any ideas how to approach it.

Can you suggest any good sites for javascript tutorials, and advanced
javascript

Thanks.
 
M

marss

Prof said:
I am just learning javascript, and i wanted to strike a text in a
normal <p> tag using javascript.
I have tried to use a old script found in th forums , it works ,
although it uses the <a> tag and hence has a underline. I wanted to
find a script in which i can check a checkbox and the text nearby will
get striked automatically.

Can anyone help here please. Or suggest what i should use. Cause i am
not getting any ideas how to approach it.

Can you suggest any good sites for javascript tutorials, and advanced
javascript

Thanks.


<html>
<head>
<script>
function changeText(strike)
{
var pnl = document.getElementById("p1");
if (strike && pnl.firstChild.tagName != "S")
pnl.innerHTML = "<S>"+ pnl.innerHTML+"</S>";
if (!strike && pnl.firstChild.tagName == "S")
pnl.innerHTML = pnl.firstChild.innerHTML;
}
</script>
</head>
<body>
<input type="checkbox" onclick="changeText(this.checked)">
<p id="p1">
asdg dfasg sfgh gdfg
</p>
</body>
</html>
 
R

RobG

marss said:
<html>
<head>
<script>
function changeText(strike)
{
var pnl = document.getElementById("p1");
if (strike && pnl.firstChild.tagName != "S")
pnl.innerHTML = "<S>"+ pnl.innerHTML+"</S>";

The S element is deprecated, so not a good choice. Why not simply set
the style of the element?

Consider:

<script type="text/javascript">

function strikeText(el, doIt) {
if (typeof el == 'string') el = document.getElementById(el);
el.style.textDecoration = (doIt)? 'line-through':'';
}

</script>

<input type="checkbox" onclick="strikeText('s1', this.checked);">
<span id="s1">Some text</span>


But adding/removing a CSS class with the appropriate rule would be
better.
 
V

VK

marss said:
You're right.

If it's some version comparison feature like in word processors then
<del> and <ins> markup is the most appropriate IMO. Sumply style <del>
and <ins> in the way you want.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top