Replacing <div> content by external html file with Javascript -


i'm bit rusty on html , javascript , can't seem 1 right. simple approach took works fine, want more flexible. here simple approach:

<head>      <script>         function loadcontent(a){             document.getelementbyid(a).innerhtml='<object type="text/html" data="home.html" ></object>';         }     </script> </head>  <body>      <div id="topbar">          <a href ="#" onclick="loadcontent('content')"> home </a>      </div>     <div id ="content"> </div>  </body> 

this works fine. however, want desired document variable of function. here stuck. has "" , '', have not been able find answer. here 'desired' situation:

<head>      <script>         function loadcontent(a, b){             document.getelementbyid(a).innerhtml= b;         }     </script> </head>  <body>      <div id="topbar">          <a href ="#" onclick="loadcontent('content', '<object type='text/html' data='home.html' ></object>')"> home </a>      </div>     <div id ="content"> </div>  </body> 

can me out?

thanx

try:

<a href ="#" onclick="loadcontent('content', '<object type=\'text/html\' data=\'home.html\' ></object>')"> home </a>  

basically escape quotes.


Comments