Page 1 of 1
JS InnerHTML vs jQuery html()
Posted: Mon Aug 02, 2010 1:13 am
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.
Re: JS InnerHTML vs jQuery html()
Posted: Mon Aug 02, 2010 4:59 am
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.
Re: JS InnerHTML vs jQuery html()
Posted: Mon Aug 02, 2010 11:16 am
by JonathanStanton
oh I was just wondering what you would use, if their are any advantages or disadvantages in using one or the other
Re: JS InnerHTML vs jQuery html()
Posted: Mon Aug 02, 2010 3:15 pm
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.
Re: JS InnerHTML vs jQuery html()
Posted: Tue Aug 03, 2010 6:59 am
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.
Re: JS InnerHTML vs jQuery html()
Posted: Tue Aug 03, 2010 7:00 am
by klevis miho
I would use (and learn jQuery).