Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Javascript JavaScript strike method

Related Tutorials


 
 

Share on Google+Share on Google+

JavaScript strike method

Advertisement
JavaScript strike() method can be used to strikethrough the string. It converts the string in the format like "Hello".

JavaScript strike method

     

JavaScript strike() method can be used to strikethrough the string. It converts the string in the format like "Hello". 

Syntax:

 string_object.strike();

Where string_object is the object at which we have to apply the strike() method. It returns the copy of string sandwiched between the pair of <strike> tag.

Description of code:

We will illustrate you the use of strike() method with a very simple example here. We have created an input text box which takes the string input by the user and as soon as we click on the button "Strike text", it calls the method strikeText() as defined in the JavaScript.

 function strikeText()
   {
  var textToStrike = document.getElementById('txt').value;
  document.getElementById('divId').innerHTML
  = textToStrike.strike(); 
  return true;
  }

First line of the function describes that we have created a variable "textToStrike" and thereafter we have taken the "divId" element's reference to show the string in strikethrough within "divId". Here is the full description code for "strikeMethodExample.html" as follows : 

<html>
 <head>
  <title>strike() method example</title>
   <script language="JavaScript">
     function strikeText()
     {
      var textToStrike = document.getElementById(
                           'txt').value;
      document.getElementById('divId').innerHTML
                          = textToStrike.strike(); 
      return true;
    }
   </script>
 </head>
<body>
<div style="background: #ff9900; width:'100%';"
      align="center">
  <font color="#0000ff" size="12pt">
    <b>strike() Example</b>
  </font>
</div>
<center>Insert any text 
 <input type="text" id="txt" /><br>
 <div id="divId" style="backgroud :#ccccff">
 </div>
 <input type="button" value="Strike text" 
  onClick="return strikeText();"/>
</center>
</body>
</html>

Output:

Input any text to apply strike() method over it.

As shown in output that it has stroked the text input.

Download Source Code

     

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: April 3, 2006

Related Tutorials

Discuss: JavaScript strike method  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com