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

  • SEARCH
  • Home
  • 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 8441697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:37:52+00:00 2026-06-10T08:37:52+00:00

ı know the topic is not specific. let me tell you. ı have a

  • 0

ı know the topic is not specific. let me tell you.

ı have a text box and button. when you enter something and click button its creating div and appending it to another div. but the problem is its must append it to top of the page. its going to be second div.

jquery code:

$('#send').click(function() {
   var not=$('#not').val();

   $.ajax({
    type:"POST",            
    url: "some.php?islem=not",
    data:{not:not},
    success: function(result){
        $('#comment_box').append('<div class="comment">'+not+'</div>'); 
    }   
   });
});

html code:

<textarea style="width: 794px; height: 48px;" id="not"></textarea>
<input type="button" value="Yolla" style="margin-top:35px;" id="send"/>

<div id="comment_box">
    <div class="comment">comment-1</div>
    <div class="comment">there is comment in here-2</div>
    <div class="comment">there is comment in here-3</div>
    <div class="comment">there is comment in here-4</div>
    <div class="comment">there is comment in here-5</div>
</div>

when ı add something the new div is shown after comment-1, ı want it to be first. because its the latest comment and it must be first, at the top of the page.

sory for bad english.

  • 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-06-10T08:37:53+00:00Added an answer on June 10, 2026 at 8:37 am

    I’d suggest more or less the same thing, but with a slight twist on your originally-posted code:

    $('<div />', {'class' : 'comment'}).prependTo('#comment_box');
    

    The element-creation specifies the element to be created, and as the second parameter takes an object defining the attribute/properties with which that element should be created.

    This makes it a little easier to maintain code in the long run (in large projects), though admittedly this is, more or less, a purely personal opinion with no metrics with which I can offer support for this approach.

    Edited in response to question from OP:

    where should ı insert text? ı want to add div with data.

    To add text to the element, there’s two approaches:

    $('<div />', {'class' : 'comment', 'text' : not}).prependTo('#comment_box');
    

    JS Fiddle proof-of-concept.

    Or:

    $('<div />', {'class' : 'comment'}).text(not).prependTo('#comment_box');
    

    JS Fiddle proof-of-concept.

    Edited in response to question from OP:

    can ı ask 1 last question. ı want to add after not but its not working

    For this, you need to get a reference to the div you inserted and then, simply insert the br element after that div:

    var newDiv = $('<div />', {'class' : 'comment'}).text(not).prependTo('#comment_box');
    $('<br />').insertAfter(newDiv);
    

    If you want the br within the div you’ve just created, then simply use append():

    $('<div />', {'class' : 'comment', 'text' : not}).append('<br />').prependTo('#comment_box');
    

    Or:

    $('<div />', {'class' : 'comment'}).text(not).append('<br />').prependTo('#comment_box');
    

    References:

    • append().
    • jQuery(html, props), it’s the last part of that section.
    • prependTo().
    • text().
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this is a recurrent/classical topic but I did not found anything that
I know implementing database is a huge topic, but I want to have a
I used the search, and the specific topic has not been covered before to
I know this topic has been discussed a lot , but I have a
I know this topic has been pounded as I have read gillions of posts
I know this topic has been discussed but I think it has some differences.
I know the topic I started is too subjective. But I just wanted some
I know this topic was descibed few times so far, but here is mine
I know this topic is bit old, but i did surf the web and
This is my first post. I know this topic has been discussed before in

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.