Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strike out a word in javascript when item clicked

Strike out a word in javascript/jquery when item clicked.

So I am clicking and item ,the item fades out but in the same time I want the text to strike out.

Ex. I have an apple(image) and a apple(text). When I click on the apple I want the image to fade out and the text to strike out.

<div id="items">
  <p>Apple</p>
</div>
<div id="content">
  <div class="box" id="pic1"> <img src = /images/apple.png  /></div>
    <script>
      $("#pic1").click(function () {
        $("#pic1").fadeOut("slow");
       });
    </script>

This is my code until the image fades out but I cannot figure out how can I make the text to strike out???

like image 772
Beslinda N. Avatar asked Apr 08 '13 23:04

Beslinda N.


2 Answers

Try putting this after the fade.

$(this).parents("p").css("text-decoration", "line-through");
like image 78
tymeJV Avatar answered Nov 17 '22 05:11

tymeJV


jsFiddle Demo

You could wrap the text in <del>

$("#pic1").click(function () {
 $("#items p").wrap("<del>");
 $("#pic1").fadeOut("slow");
});
like image 3
Travis J Avatar answered Nov 17 '22 03:11

Travis J