What is the most straightforward way to assign html to an HTML element?

39 Views Asked by At

I have an html file in my project's Contents folder. I have a div with an ID of "FictionContent" that I want to assign the contents of that HTML file.

Is the following a good way to do that:

$('#FictionContent').html('Content/huckfinn.html');

?

Will the jQuery understand "Content" as a subfolder and thus know where to grab the html? If not, what is a workaround for doing something as similar as possible?

2

There are 2 best solutions below

0
On BEST ANSWER

Try this:

$('#FictionContent').load('Content/huckfinn.html');
0
On

Two examples over here:

Content from a variable

var mycontent = "Hello World";
$('#FictionContent').html(mycontent);

Content from your html file

$('#FictionContent').load('Content/huckfinn.html');