Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3939392
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T00:17:41+00:00 2026-05-20T00:17:41+00:00

i am trying to replace the content of a div with the content of

  • 0

i am trying to replace the content of a div with the content of another div(which is hidden). The code works for the first time only but the second time doesn’t work at all.
I have a div where the titles of some articles are scrolling. I want to achieve that:everytime i am going to click the title of an article its content(the content is in hidden div) is going to appear in another div with the id=”sreen”.

<script type="text/javascript"> 
//everytime you click the title of an article

$("a.title").live("click", function(){

//replace the content of div screen with the content of an article

$('div#screen').replaceWith($(this).next('div.content'));


    });

</script>

Any ideas???

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T00:17:42+00:00Added an answer on May 20, 2026 at 12:17 am

    Using .replaceWith will effectively remove div#screen. So using .html() will be what you want to do to maintain the element div#screen.

    You mentioned that your formating is not working correctly which leads me to believe you have css classes on div.content. Calling .html() on div.content will ommit the root node of div.content.

    <div class="content">
     <span>some text</span>
    </div>
    

    $("div.content").html() will produce <span>some text</span>

    If my assumptions are correct you might want to look at using clone() which will clone the current object without events or clone(true) to include any data and events.

    var $content = $(this).next('div.content').clone();
    $content.css("display", "block");
    $('div#screen').html($content);
    

    Another way of doing this would be use .outerHTML

    $("a.title").live("click", function() {
      $('div#screen').html($(this).next('div.content')[0].outerHTML); 
    });
    

    Example on jsfiddle.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to replace a div's content with a sourceURL and it works in
I'm trying to replace the content of a WPF grid control by another WPF
I am trying to replace div elements with button elements to improve accessibility, but
I am trying to replace content inside particular div tags (id=dd-header) with a comment.
I'm trying to write some code which replaces old content with a placeholder while
I am trying to replace a large string in groovy. But can't get it
I am trying to load just the contents of a <div> into another <div>
I'm trying to do a little javascript trick to fade out a div, replace
I'm using a simple piece of code $(container).load(url, function(){ callback();}) to replace the content
Am trying to replace content with empty using this regular expression. objRegExp.Pattern = <(?>/?)(?!(p|strong)(>|\s))[^<]+?>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.