Click here to Skip to main content
14,107,154 members
Rate this:
Please Sign up or sign in to vote.
See more:
i want to replace




can it be happen ? i want to do it between script tags, i dont want to make from from other programs like c, python. i m beginer i dont know anything.

What I have tried:

a = document.write()

b = a.toString();

c = b.split('',-1);

w= w().toString().split('',-1);

w = a;

means whenever i will write this


then it must behave like this on browser


without typing


can it be happen ?
Updated 26-Jul-16 9:21am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Yeah it's possible, just create a wrapper function. Not sure why you'd want to this however, but...
  // define it
  function w(markup) {

  // call it
  w("<p>Hello World</p>");
Jeremy Falcon 27-Jul-16 13:08pm
In this example, you're close but the "markup" parameter should be what you want to show rather than the ID. Also, for the id() function you'll need to return the value. And last but not least you need to make sure the DOM element (the paragraph in this example) exists before you can call it. Try something like this...

function id(element) {
return document.getElementById(element);

// this cannot be called yet because the p element does not exist
id("demo").innerHTML = "i will not show";

<p id="demo"></p>

// now the dom element exists
id("demo").innerHTML = "i will show";
prasad sawant 27-Jul-16 14:28pm
wow! it works great.. thanks..

all i have understood that

1. the return syntax must be written

2. element must be there on top of script tag

i will understand it more by time i think..

i have question..

can i make this..

.innerHTML as .in()
.length as .len
.toString() as .str()

and so on..

means when will i type


it will show..


instead of..

Jeremy Falcon 27-Jul-16 15:43pm
Yes you could do that, with one notable difference, .innerHTML and .length are properties. As such you'd have to either write a wrapper method for it too, or a new prototype that calls the real one underneath the hood, but on the same object. Since code is worth a thousand words...

function id(element) {
return document.getElementById(element);
} = function(markup) {
this.innerHTML = markup;

<p id="demo"></p>

// now the dom element exists
id('demo').in('i will show');
prasad sawant 28-Jul-16 9:32am
i didnt get it well but i hope i will know it soon, what i got here is

new syntax-- Object.prototype and this

thank u very much
prasad sawant 29-Jul-16 7:58am
read my new post, hope u have answer of it.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

thank u very much its working!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web04 | 2.8.190518.1 | Last Updated 26 Jul 2016
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100