Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

How to append data in div w/o duplicating the data?

javascript jquery

Best Answer WingedPanther73, 20 April 2015 - 04:39 AM

"Append" means "add to the end, regardless of what came before." It sounds like you're saying you do NOT want to append. You'll need to check to see if your data is already in the div, and if so, append, otherwise not.

Go to the full post


This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1 keanallen

keanallen

    CC Newcomer

  • Member
  • PipPip
  • 18 posts

Posted 19 April 2015 - 02:34 AM

Hi, it's my first time here. My question is on how to append data in a div without duplicating the data because Everytime i append the data it will be duplicated.


For example my data is like this:

<script>
   setInterval(sample, 2000);
   var data = "This is the data that i want to append.";
   function sample()
   {
      $('#latest').append(data);
   }
</script>

<div id='latest'></div>

It works but it will be duplicated. Please help me geeks :) Thank you. I'll wait


Edited by keanallen, 19 April 2015 - 02:45 AM.


#2 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts

Posted 20 April 2015 - 04:39 AM   Best Answer

"Append" means "add to the end, regardless of what came before." It sounds like you're saying you do NOT want to append. You'll need to check to see if your data is already in the div, and if so, append, otherwise not.


Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#3 wim DC

wim DC

    Roar

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 2681 posts

Posted 20 April 2015 - 04:59 AM

To add to what WingedPanther73 said, you might want to try .text(data) or .html(data) instead of append



#4 keanallen

keanallen

    CC Newcomer

  • Member
  • PipPip
  • 18 posts

Posted 20 April 2015 - 06:05 AM

Thank you for the reply guys  :)  . I already solved my problem yesterday. What I did is compare the data and do some conditions.