0

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
1
  • 4
    Do you get any errors in the Javascript console? Commented Jun 30, 2012 at 22:14

1 Answer 1

3

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.