0

Dear Sirs,

I have been playing around with this so far, and couldn't get a good solution.
Well I have my simple code :

<html>
<body>


<a href="#" onClick="document.write('P');>P</a>

<div id="a">a</div>

</body>
</html>

Well, normally, this onClick event directs us to a new empty page showing a 'P'. I want this 'P' to be shown in the div tag below.

Could you please help me?

Thanks in advance,

Tibor

4
Contributors
4
Replies
7
Views
5 Years
Discussion Span
Last Post by JorgeM
0

You don't write a document in a paragraph. It's just something that you don't normaly do.
The "document.write" writes a new document over the previous. Not inside the existing one. Meaning you can't have another document in a document.

I believen you might want to read and try to use the "innerHTML" command instead.

1

In the line <a href="#" onClick="document.write('P');>P</a> you are missing the closing " for the onclick event.

If you set the onclick listener to "document.getElementById('a').innerHTML += 'P'" then it should add a letter 'P' to the div each time you click on it.

<html>
<body>
<a href="#" onClick="document.getElementById('a').innerHTML += 'P'">P</a>
<div id="a">a</div>
</body>
</html>

Edited by dcdruck: Added full source

0

Thanks for your reply, I don't usually use Jscript, but innerHTML does nothing with my document, does it work alone, or do I have to put some other code after / before that?

@dcddruck Thank you it works now!

Edited by tibormarias: Later got the solution.

0

Can you elaborate on what you mean by "does nothing with my document"? In the examples that were provided to you, it should be evident that what is being done here is accessing the content between the starting and closing tag of the element with an id = "a". innerHTML is that property that you use to access the content.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.