JS InnerHTML vs jQuery html()

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
JonathanStanton
Forum Newbie
Posts: 10
Joined: Wed Jul 21, 2010 10:07 am

JS InnerHTML vs jQuery html()

Post by JonathanStanton »

for those of you guys who know jQuerys html class, what would be better to do, using:

[text]document.getElementById('userMsg').innerHTML = userInput;
or
$("#userMsg").html(userInput);[/text]

the purpose of this will be to dynamically generate and insert a small piece of php/html code from database.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Re: JS InnerHTML vs jQuery html()

Post by superdezign »

What do you mean by "better"?

If you mean faster, then jQuery will almost always be slower.
If you mean less code for you to write, jQuery will always have less code to write.
JonathanStanton
Forum Newbie
Posts: 10
Joined: Wed Jul 21, 2010 10:07 am

Re: JS InnerHTML vs jQuery html()

Post by JonathanStanton »

oh I was just wondering what you would use, if their are any advantages or disadvantages in using one or the other
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: JS InnerHTML vs jQuery html()

Post by califdon »

superdezign just answered that for you. In general, if you're coding the rest of your application using jquery, I'd recommend that you use that. If you're not, I wouldn't. If you're asking a general question, "Should I use jquery?", there is not much agreement among developers. Some swear by it, others get along nicely without it. A lot depends on whether you're going to be writing a whole lot of JS code for somewhat fancy displays, etc. Jquery is very useful for that.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Re: JS InnerHTML vs jQuery html()

Post by superdezign »

Or, if your like me, your secretly developing a JavaScript framework that is similar to jQuery, but almost faster (in other words, still slower lol) and with "improved" syntax.
klevis miho
Forum Contributor
Posts: 413
Joined: Wed Oct 29, 2008 2:59 pm
Location: Albania
Contact:

Re: JS InnerHTML vs jQuery html()

Post by klevis miho »

I would use (and learn jQuery).
Post Reply