String.prototype.strike() is deprecated, and the HTML <strike> element it creates is obsolete. Use <del> for deleted content, <s> for content that is no longer accurate/relevant, or CSS for purely visual decoration.
const text = "Old price: $50";
console.log(text.strike()); // legacy only
string.strike()
Use <del> when content represents a deletion or edit. Use <s> when text is no longer accurate or relevant but is not an editorial deletion.
const oldPrice = document.createElement("s");
oldPrice.textContent = "$50";
document.body.append(oldPrice);
.old-price { text-decoration: line-through; }
checkbox.addEventListener("change", () => {
price.classList.toggle("old-price", checkbox.checked);
});This modernizes the original checkbox-driven example. See JavaScript checkbox handling.
See the original strike demo when maintaining legacy code.
Previous / String Reference Next related topic
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.
| Sudhir | 22-09-2012 |
| if i want to check all/ unchecked all then how to work check box for Strikethrough text in javascript | |
| Kiran | 06-10-2012 |
| Given in a short & simple manner, this is what i am looking for Thank you to the author | |
| stan | 09-08-2013 |
| Thanks for this! | |
| Daniele | 26-01-2014 |
| Is there a possibility to have the browser to persistently save the action of strikethrogh? Thank you for your time | |
| smo1234 | 27-01-2014 |
| Yest it is possible, we can use Ajax with any server side script to update database. | |