I am trying to load an external .htm file to a div on my main page, and I have used the following code:
<a href="#file.htm" onclick="$('#content').load('file.htm')">Link</a>
It works in firefox, but not in chrome and IE. Can anyone help me?
Darin Dimitrov
1.0m277 gold badges3.3k silver badges3k bronze badges
asked Jun 30, 2012 at 22:13
user114158
1971 gold badge1 silver badge6 bronze badges
-
4Do you get any errors in the Javascript console?millimoose– millimoose2012年06月30日 22:14:59 +00:00Commented Jun 30, 2012 at 22:14
1 Answer 1
Why not
html
<a href="file.htm" class="ajax">Link</a>
and add a script
<script type="text/javascript">
$(function(){
$('.ajax').click(function(e){
e.preventDefault();
$('#content').load( this.href );
});
});
</script>
this way you can set a class ajax to all the links that load inside the #content area and it handle all of them..
Could it be that the reason it does not work is that you click too soon and the jquery is not yet loaded ?
answered Jun 30, 2012 at 22:19
Gabriele Petrioli
197k35 gold badges276 silver badges331 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-js