Monday, 18 July 2011

Load contents from another page using jQuery

index.html

<!DOCTYPE html>
<html>
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
        <script type="text/javascript" src="jfunc.js"></script>
      
    </head>
    <body>
        <input type="button" value="Load" onclick="load_file('t.txt','#area')"/>
        <div id="area"></div>
    </body>
</html>

The function load_file() which is stored in another js file is called from inside the onclick event
of the input in the index.html file. The filename and the id i.e, place where the information is
to be placed is passed as arguments.

jfunc.js

function load_file(file_name,element){
   $(element).load(file_name);
    
}

No comments:

Post a Comment