1

I want to replace the content of the #textoGrande div with an external file.

I intend to use each menu li to call the included div files, avoiding the page to be reloaded. My javascript include is empty... I don't know how to get started...

Here's the html structure:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<link href="css/style.css" media="screen" rel="stylesheet" type="text/css">
 <script type="text/javascript" src="http://code.jquery.com/jquery-1.5.1.min.js"></script>
<script type='text/javascript' src='include/javascript.js'></script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Opera</title>
</head>

<body>
    <div class="main">
        <div id="header">

            <h1 id="logo">
                <a href="#">Linux Logo</a>
            </h1>

            <ul>
                <li><a href="#">Home</a></li>
                <li><a href="#">News</a></li>
                <li><a href="#">About</a></li>
                <li><a href="#">Contact</a></li>
                <li><a href="#">Support</a></li>
            </ul>

            <div id="player"></div>

        </div>
    <div id="imagen"></div>
    <h2 id="textoGrande"><p>Opera ahora<br /> mas acojedor...</p>
    </h2><h3 id="textoPequeno"><p>En su nueva versión, Opera apuesta por un nuevo diseño y pestañas visuales, un motor más veloz que incrementa su velocidad en un 40% frente a su anterior versión y un mejor soporte de estándares.</p>

    </h3></div>


</body></html>

2 Answers 2

2
$("li a").live("click", function(){
       $("#textoGrande").load($(this).attr('href')+' body');    
       return false;
});
Sign up to request clarification or add additional context in comments.

10 Comments

Thanks, but it's only loading itself # ... How do you make it work for an specific html?
If I do that, for example <li><a href="test.html">Home</a></li> The entire page loads, the javascript doesn't seem to make any effect.
Still not working, what am I doing wrong? Please check the live sample: gabrielmeono.com/working
@Gabriel: Try to use new jQuery, not sure if it will work but try to change 1.5.1 to 1.7
I thought it was, but not quite, It's removing the old div, but it does load the new content...
|
0
$(document).ready(function() {
  $("li a").click(function() {
    $("#textoGrande").load($(this).attr('href'));
  });
});

1 Comment

It contains a sintaxis error in line 3. And doesn't do anything, the page loads entirely.

Your Answer

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.