Posted By

1man on 01/08/07


Tagged

simple heading tutorial


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

vali29


Extend the String Method Example


 / Published in: JavaScript
 

Simple extension of the string method using string.prototype.

  1. function fmtHeading(level) {
  2. stringtext = this.toString();
  3. starttag = "<h" + level + ">";
  4. endtag = "</h" + level + ">";
  5. return starttag + stringtext + endtag;
  6. }
  7.  
  8. String.prototype.heading = fmtHeading;
  9. document.write("This is a heading!".heading(2));

Report this snippet  

You need to login to post a comment.