0

I have a template that I want to render inside html element on click of element. I want to do something like ( I am using jquery):

$(".btn")on("click", function(){ 
     $("#element").html(partial_template.html)
});

Buto this of course wont work. How can I achieve this?

EDIT: I am using Django, if this matters!

3
  • 2
    You want to take a look at Ajax/API Calls. Commented Jun 5, 2017 at 16:24
  • You can either do it with AJAX or with a library like Handlebars which lets you define your HTML in a template that is then properly injected as a partial. I would recommend using handlebars. Commented Jun 5, 2017 at 16:42
  • Possible duplicate of jQuery.load to load HTML file Commented Jun 8, 2017 at 10:35

1 Answer 1

1

Use .load() function , make sur to set the right path to your html tpl .

$(".btn").on("click", function(){ 
     $("#element").load("path_to_your_html_folder/partial_template.html");
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.