Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using <strike> or <del> in a select box

Tags:

html

xhtml

Is there anyway to strike out text in a drop down. I'm making an commerce app and looking for a way to demonstrate that an item is on sale. I'd like to do this by showing the old price and the striking this out and showing the sale price next to it.

I tried something like this

<select>
    <option value="1">Small Box 10.99</option>
    <option value="2">Large Box <del>19.99</del> 15.99</option>
</select>
like image 824
Alex Avatar asked Oct 05 '11 10:10

Alex


3 Answers

You could use the Unicode combining character U+0336 LONG STROKE OVERLAY:

"19.99".replace(/\d/g, function (digit) { return digit + "\u0336" })

Result: 1̶9̶.9̶9̶

(It doesn’t look so good when you apply it to the period; that’s why I left that out.)

Here are all the digits with the stroke applied, if you want to just copy them into your server-side script:

0̶1̶2̶3̶4̶5̶6̶7̶8̶9̶
like image 82
Daniel Brockman Avatar answered Nov 12 '22 06:11

Daniel Brockman


This is not possible if you're using a standard HTML select. Any markup within the <option> tag will be ignored:

<!-- The style in the span tag is completely ignored -->
<option value="1"><span syle="color:red">Small</span> Box 10.99</option>

The closest you're going to get to your desired functionality with the HTML select is by using the "disabled" property. Example:

<select>
    <option />
    <option value="1" disabled="disabled">Small Box 10.99 (Original Price)</option>
    <option value="1">Small Box 6.99 (Sale Price)</option>
</select>

Here's a working fiddle to demonstrate.

like image 5
James Hill Avatar answered Nov 12 '22 06:11

James Hill


No. With HTML standard elements you can't have that kind of functionality. To solve that problem you have to create your own element.

like image 1
KodeFor.Me Avatar answered Nov 12 '22 06:11

KodeFor.Me