ivy ong
ivy ong

Reputation: 101

Jquery navigation using html()

    $('.page').on('click',function(){
       $(this).next('.content').css('display','block');
           $('body').empty('');
           var post = $(this).next('.content').css('display','block');
           post.appendTo('body');

    });

How to clear all other thing except the .content so it's like u nagivated to a new page? I tried above code but my logic flawed. I'm new to jquery.

Upvotes: 0

Views: 37

Answers (2)

Musa
Musa

Reputation: 97727

Maybe you can detach the node before clearing the page then append it back.

$('.page').on('click',function(){
   var content = $(this).next('.content').detach();
   $('body').html('').append(content.css('display','block'));
});

Upvotes: 1

Nicola Ferraro
Nicola Ferraro

Reputation: 4189

$('.page').on('click',function(){
   $('body').empty();
   // you have just deleted the page, how would you find other objects in the page ?
   // $(this).next('.content').css('display','block');
   // Try to .append new elements to the body
});

Upvotes: 1

Related Questions