/ Published in: JavaScript
Simple extension of the string method using string.prototype.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function fmtHeading(level) { stringtext = this.toString(); starttag = "<h" + level + ">"; endtag = "</h" + level + ">"; return starttag + stringtext + endtag; } String.prototype.heading = fmtHeading; document.write("This is a heading!".heading(2));