JavaScript String strike(): Legacy Reference

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

Legacy strike() syntax Top ↑

string.strike()

Choose s or del by meaning Top ↑

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.

Create strikethrough text with the DOM Top ↑

const oldPrice = document.createElement("s");
oldPrice.textContent = "$50";
document.body.append(oldPrice);

Visual line-through with CSS Top ↑

.old-price { text-decoration: line-through; }

Checkbox-controlled example Top ↑

checkbox.addEventListener("change", () => {
  price.classList.toggle("old-price", checkbox.checked);
});

This modernizes the original checkbox-driven example. See JavaScript checkbox handling.

Legacy demo reference Top ↑

See the original strike demo when maintaining legacy code.

Previous / String Reference Next related topic




Subscribe to our YouTube Channel here



plus2net.com







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.



✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer