How to use a text file's contents in HTML as text [duplicate]


Tags: javascript,jquery,html,css,text

Problem :

This question already has an answer here:

I am making a website template and I though of a cool new trick to save time when changing large text files. I want to have a separate plain text document that when the page loads, it contents will be transferred to my paragraph.

Example:

The text document:

Introducing the new red glasses.

The paragraph's text will be loaded and be the same as the text documents like so:

<p> Introducing the new red glasses. </p>

So how can I do something like this? Is it even possible? I am willing to use HTML, CSS, jQuery and Javascript.



Solution :

You could use AJAX:

$.get( "mytext.txt", function( txt ) {
    $( "#myParagraph" ).text( txt );
});

You will need to host your HTML from a server, or otherwise it won't work


    CSS Howto..

    how to make edges round in CSS?

    how to add a class to buttons attribute using css or jquery

    CSS+HTML: How to draw table/cell border

    How to vary the tone of an image dynamically using only css?

    How to parse CSS font shorthand format

    How to use a Video as text background in css

    How to switch left and right in a css file?

    How to restrict zoom of webpage to stretch when iPhone and Android in landscape orientation?

    How to use background image in CSS?

    How to override external css?

    How to use both fixed and stretchy CSS content

    How select/option open in top?

    How to remove border from appearing around the image?

    How to include all css kept in a direcotry?

    Something in my CSS is causing a random white bar to appear, how do I fix it?

    How to make a hidden border side inherit border properties in CSS

    How to give sentence case to sentences through CSS or javascript? [closed]

    How to overlap a div to an another div without changing their positions - Css

    CSS - how to set up header images as use eg. Facebook?

    How to get Floating DIVs inside fixed-width DIV to continue horizontally?

    My sidebar is not going to right of my page, but to my left. How do I fix this?

    How to check if element contains specific class attribute

    How to use getElementId on and ID's Element

    SVG + CSS - how to include in HTML and scale & color?

    jQuery & CSS: how to convert this drawer menu from left to right?

    How to fix some issues with printing very basic HTML

    How can I add a red border to this box (an a tag) when the mouse is on (hover) the box?

    How to completely fill screen with smaller elements?

    How to create rating system using only css [duplicate]

    how to set CSS border-left outside of box