Saturday, June 1, 2024
 Popular · Latest · Hot · Upcoming
175
rated 0 times [  182] [ 7]  / answers: 1 / hits: 16027  / 13 Years ago, tue, february 21, 2012, 12:00:00

i try to make text strikethrough with javascript.
I know nothing about Javascript and try to search on the net how to that.



 <script language=JavaScript>
function recal(val,sum)
{
if(sum == true)
{
var total = parseInt(document.getElementById(total).innerHTML, 10);
total+=val;
document.getElementById(total).innerHTML=total;
}
else
{
var total = parseInt(document.getElementById(total).innerHTML, 10);
total-=val;
document.getElementById(total).innerHTML=total;
var pnl = document.getElementById(totalEvents);
}



var pnl = document.getElementById(totalEvents);
var pnl2 = document.getElementById(eventCategory);
var pnl3 = document.getElementById(nameID);

**strikethrough starts here**
if (!sum && pnl.firstChild.tagName != S && pnl2.firstChild.tagname !=S)
{
pnl.innerHTML = <S>+ pnl.innerHTML+</S>;
pnl2.innerHTML = <S>+ pnl2.innerHTML+</S>;
}
else
{
pnl.innerHTML = pnl.firstChild.innerHTML;
pnl2.innerHTML = pnl2.firstChild.innerHTML;
}



}
</script>


it makes textstrikethrough but something is wrong. Even if i choose second checkbox it affects first checkbox why :(



http://jsfiddle.net/aHH9w/ (my full html page)



enter



enter


More From » javascript

 Answers
196

You are peforming a pretty convoluted way of achieving this, something that can actually be quite easily done. If you have an HTML element, say with the id 'myelement':



<div id=myelement>Hello world</div>


To create a strikethrough, all you need to do in JS is:



var ele = document.getElementById(myelement);
ele.style.setProperty(text-decoration, line-through);


If you need to check if there is a strikethrough on an element:



var ele = document.getElementById(myelement);
var isStruck = (ele.style.getProperty(text-decoration) == line-through);


Although this is not really recommended. Use an internal variable to keep track of state.


[#87319] Sunday, February 19, 2012, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
arthur

Total Points: 729
Total Questions: 107
Total Answers: 109

Location: China
Member since Mon, Aug 22, 2022
2 Years ago
;