Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strike-through on click

Tags:

html

css

Is there a css-way to make a onclick strike-through button. So when you click a button(piece of text) selected links will get the strike-through text-decoration?

Attached image as explanation.

enter image description here

like image 994
Jeppe Pendrup Avatar asked Jun 13 '17 09:06

Jeppe Pendrup


2 Answers

Pure CSS simulating a button. When clicked, the paragraph turns red with strikethrough.

input[id=cb] {
  display: none;
}

input[id=cb]:checked~p.strikethrough {
  text-decoration: line-through;
  color: red;
}

label {
  border: thin solid darkgray;
  border-radius: 5px;
  padding: 10px;
  display: inline-block;
  margin-top: 5px;
}
<input name="cb" type="checkbox" id="cb">
<label for="cb">Click me</label>
<p class="strikethrough">Paragraph 1</p>
<p>Paragraph 2</p>
<p class="strikethrough">Paragraph 3</p>
like image 149
Gerard Avatar answered Oct 20 '22 16:10

Gerard


You can achieve this on any element using JS. Also, not only you can strike onClick but also remove the striked content back to its original state.

$(function(){
  var $curParent, Content;
  $(document).delegate("span","click", function(){
    if($(this).closest("s").length) {
      Content = $(this).parent("s").html();
      $curParent = $(this).closest("s");
      $(Content).insertAfter($curParent);
      $(this).closest("s").remove();
    }
    else {
      $(this).wrapAll("<s />");
    }
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
<span>click</span>/<span>click</span>
</div>
like image 27
Dhruvil21_04 Avatar answered Oct 20 '22 16:10

Dhruvil21_04