How to include a file with jquery?

Posted on 2011-04-29
Last Modified: 2012-08-12
I am wondering what is the jquery equivelent to php's include:

include 'sidebar.php';

I have a link:

<a href="">+ Add A Sub Category</a>

But I am not sure what I would set the href to in order to get the included file.  Anyone got some advice for this?
Question by:FairyBusiness
    LVL 27

    Expert Comment

    by:Lukasz Chmielewski
    LVL 20

    Accepted Solution


    The load method should do what you want:

    $("#load-me").load( "" )

    <div id="load-me"></div>

    Author Comment

    Ok, I changed my function to this:

    $("#sub").click(function() {
          content = "<div class='sub'></div>";

    My thought is every time my link (#sub) is clicked

     <a href="" id="sub">+ Add A Sub Category</a>

    It would add a div to my form

    Then it would load the included file into that div with a class of sub.

    Then it would finally fade the div in.  The reason I am doing it like this is because there may be many sub categories so I need it to be able to be entered in to the form multiple times.  But its not working.  Any ideas on how I could achieve this?

    Author Comment

    Here is the function in my library (I didnt get very far with it yet)

    function update_materials() {
    	global $conn, $message, $errors, $error;
    	if(empty($errors) && isset($_POST['submit'])) { // Perform Update
    		$materials = $_POST['materials'];

    Open in new window


    Author Comment

    Nevermind that comment was suppose to be for another question. ..

    Author Closing Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Course: Create Mobile App Prototypes with Adobe XD

    This is a project-based course: we go through all the steps of creating a prototype from start to finish, using all the tools and features currently available in Adobe XD. You can complete the course in less than a day, plus all project files and fonts are included.

    In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
    Article by: DanRollins
    This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (, we'll extend the program by adding a depth-…
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now