Samer El Gendy
Samer El Gendy

Reputation: 1683

loading page inside a div using jquery

i am creating a javascript method which loads page contents inside a div container using jquery and it works properly, but when i click at any button inside the div itself, it redirects to new page?

that's the method:

<script type="text/javascript">
            $('a').click(function() {
                var page = $(this).attr('href');
                $("#content").fadeOut('slow', function(){
                    $("#content").load(page, function () {
                        $(this).fadeIn('slow');
                    });
                });
                return false;
            });
        </script>

anyone can solve this problem?

Upvotes: 2

Views: 973

Answers (2)

user964565
user964565

Reputation:

You should use iframe instead. When you use a div like page, you just load content on it, not load page.

Upvotes: 0

GillesC
GillesC

Reputation: 10874

You are binding only element present on page loadnot ones created afterwards by using click if you use this instead it should work

$('a').live('click', function(){});

Basically live will bind to all a tags even newly created ones.

Upvotes: 2

Related Questions