0
    $('.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.

3
  • 1
    try $('.page').html(''); instead of $('body').html(''); Commented Dec 30, 2014 at 2:29
  • @Cattla .page is a link Commented Dec 30, 2014 at 2:35
  • .empty(''); should be .empty(); Also note than once you .empty() the body element, there's nothing more to retrieve, so yoru latter var post = will not get any desired element. Commented Dec 30, 2014 at 2:44

2 Answers 2

1

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

4 Comments

ah the .css() doesn't fire.
What if I want to go back?
@Musa :D "rel.the page" made my day! :)
bad UX, I think I better do a popup
1
$('.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
});

Comments

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.