Is there a jquery/javascript function that does the same that PHP echo()?

share|improve this question
Define what "the same" is. Writing to a console? Writing into the current document? Displaying a message on screen? – deceze Nov 17 '11 at 13:58
1  
First, echo is not a function (it's a language construct) and you're probably looking for document.write('Hello World');. – acm Nov 17 '11 at 13:59
If you use echo to debug, maybe console.debug is what you may need. I suggest looking into firebug if this is what you were really looking for. – Tim Nov 17 '11 at 16:31

6 Answers

up vote 4 down vote accepted

I suppose the closest is document.write() as it's native javascript.

However there are many methods of writing/amending text in the DOM, such as innerHtml(), innerText() and outerHtml(), as well as jQuery's html() and text().

share|improve this answer
I wouldn't call document.write native JS though - document is by definition using the DOM, even if what you then do is stream text to be written. Note also that innerHtml and outerHtml are not methods but properties on the regular DOM (even though the latter is a method in jQuery). – Gijs Nov 17 '11 at 14:04

You could use

document.write(stringToWrite);

or

document.writeln(stringToWrite).
share|improve this answer

I think you're looking for:

document.write( ... );
share|improve this answer
// This is what you are looking for
document.write('Hello world');
document.getElementById('mydiv').write('Hello world');

// jQuery
$(body).append('Hello world');
$('#mydiv').append('Hello world');
share|improve this answer
document.write("text"); \\javascript syntax.

while using jquery you can view you text under any element obj.

 $("#mydiv").append($("#myElement").val());
share|improve this answer
@Pranav Hosangadi thanks for apply formatting. – Saifuddin Nov 17 '11 at 18:13

If you want to edit the content of an element use html(). You can manipulate the DOM in diffrent ways. Check the docs.

share|improve this answer

Your Answer

 
or
required, but never shown
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.