Click here to Skip to main content
15,849,543 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm using a javascript function. I want to convert it JQuery. I need help.

1. How to convert document.writeln("aaaaaaaa"); to JQuery.


1 solution

Refer - document.writeln replacement in jQuery[^].
The problem with document.writeln() is that the results will change depending on where in the page you put the script. Your code always appends text to the end of the <body>, so it doesn't have that problem, but it's also not particularly useful. (Also, writeln() doesn't append a <br>, it appends a line break. There's a difference.)

The proper way to insert text dynamically is to create an HTML element that will hold the dynamic text, and set the content of that element:
<p>Good morning <span id="userName">unknown user</span>.</p>


$('#userName').text('Mike') // or append(), or html()
Share this answer
sunpop 4-Jul-13 6:32am    
@Tadit Dash
Sorry as I'm new to JQuery, I could not get it.
For example can
be written as
if I want to write in tha span with id="userName"? BY doing so I didn't get the result as expected...
Pl, clarify! thankx
Yes... You have understood correctly. But to use jQuery, you need to refer the jQuery file.
have you added that?

And please see on the console window of FireBug in FireFox, if you have any errors or not.
sunpop 4-Jul-13 6:59am    
I didn't refer the jQuery file. Now it's working well. Thank u
Great to know that. :)
Most Welcome buddy.

Thanks a lot for accepting the answer.
sunpop 4-Jul-13 7:40am    
you are most welcome!

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

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900