0

I have an unordered list that will be used as a nav bar

<ul>
            <li><a href="content/index.html" class="selected">Home</a></li>
            <li><a href="content/about.html" class="nav_bubble">About</a></li>
            <li><a href="content/projects.html" class="nav_bubble">Projects</a></li>
            <li><a href="content/tutorials.html" class="nav_bubble">Tutorials</a></li>
</ul>

and I have some javascript to load the content into a div

<script type="text/javascript">
        $(function(){
            $("div#navcontainer > ul > li > a").click(function(e){
                e.preventDefault();
                $.ajax({
                    url: e.currentTarget.href,
                    cache: false,
                    dataType: "html",
                    success: function(data) {
                        console.log(data);
                        $("#content").html(data);
                    }
                });
            });
        });
    </script>

All of that works, the question is, what happens when I load a page from my content folder that has a link in it? It sends your browser to the page instead of loading it into the div. How can I recursivly load all links into the content div instead of sending the user directly to them?

1
  • it is unclear to me . can you provide your html code Commented Jul 3, 2011 at 6:15

1 Answer 1

1

Change:

$("div#navcontainer > ul > li > a").click(function(e){

To:

$("div#navcontainer > ul > li > a, div#content a").live('click',function(e){

"Attach a handler to the event for all elements which match the current selector, now and in the future."

Sign up to request clarification or add additional context in comments.

4 Comments

That did not seem to make a difference.
Did you try adding return false; to the end of your click listener?
Ah I completely misread your question. Long day. You'll need to add a live to the content div as well: $("div#content a").live('click',function(e){ /*load ajax into content div */...
You could combine the listeners: $("div#navcontainer > ul > li > a, div#content a").live('click',function(e){ ...

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.