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.
JS InnerHTML vs jQuery html()
Moderator: General Moderators
-
JonathanStanton
- Forum Newbie
- Posts: 10
- Joined: Wed Jul 21, 2010 10:07 am
- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
Re: JS InnerHTML vs jQuery html()
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.
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()
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()
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.
- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
Re: JS InnerHTML vs jQuery html()
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()
I would use (and learn jQuery).