admin管理员组

文章数量:1406003

I'm trying to build a Handlebars app using only JavaScript. I've noticed in there documentation, they initialize using:

var source   = $("#entry-template").html();

Is this step required or is there a way around it using only native Javascript?

I'm trying to build a Handlebars app using only JavaScript. I've noticed in there documentation, they initialize using:

var source   = $("#entry-template").html();

Is this step required or is there a way around it using only native Javascript?

Share Improve this question asked Jun 20, 2015 at 4:04 Trey HuffineTrey Huffine 2423 silver badges9 bronze badges 1
  • document.getElementById('entry-template').innerHTML? – Ry- Commented Jun 20, 2015 at 4:11
Add a ment  | 

2 Answers 2

Reset to default 5

No, it doesn't require jQuery.

Only reason why people prefer jQuery is because of ease of use with which jQuery perform various operations. It saves lots of time & additional effort.

Using handlebars with plain javscript will require some extra effort. If you have enough time then you should try out things with plain JavaScript.

Below given links might be of some help to understand things better -

http://code.tutsplus./tutorials/handlebarsjs-a-behind-the-scenes-look--net-32678

http://www.raymondcamden./2012/04/19/Demo-of-Handlebars-and-why-you-should-consider-a-templating-engine

No. If you read the example further you would see they are only using jQuery to get the HTML content of an element. This is something that could have been done in vanilla JS. Any code that follows is not jQuery. The following is the same example sans jQuery. As you can see the way Handlebars is written is unaffected.

var source   = document.getElementById("entry-template").innerHTML;
var template = Handlebars.pile(source);

本文标签: javascriptDoes Handlebars require jQueryStack Overflow