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 8863375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:57:47+00:00 2026-06-14T15:57:47+00:00

I am testing jQuery’s .append() vs .appendTo() methods using following code: $(‘div/>’, { id

  • 0

I am testing jQuery’s .append() vs .appendTo() methods using following code:

$('div/>', {
    id : id,
    text : $(this).text()
    }).appendTo('div[type|="item"]#'+id);
$('div[type|="item"]#'+id).append($(this).text());

Note that the selectors are identical in .appendTo() and .append(), yet the latter works (within the same page), while the former does not. Why?

How do I get .appendTo() to work with this type of (complex) selector? Do the two methods interpolate differently? Is there some syntax I’m missing?

I don’t want to clutter the post with impertinent code: suffice it to say that elements referenced by selectors exist, as is evidenced by the .append() method producing desired result. Let me know if more info is needed.

Thanks!

  • 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-14T15:57:48+00:00Added an answer on June 14, 2026 at 3:57 pm

    To answer the question, you don’t have an element to appendTo anything, as you’re missing characters (in your case it’s an opening angle bracket <).

    This

    $('div/>',{});
    

    needs to be

    $('<div/>',{});
    

    to create an element, otherwise it does exactly what you say it does – nothing!


    Otherwise you seem to have the order of things right, it’s like this:

    • .append() inserts the content specified by the parameter, to
      the end of each element in the set of matched elements, as in

      $(Append_To_This).append(The_Content_Given_Here);
      
    • while .appendTo() works the other way around: it insert every
      element in the set of matched elements to the end of the target given
      in the parameter, as in

      $(The_Content_Given_Here).appendTo(Append_To_This);
      

    There’s also .prepend() and prependTo() which works exactly the same, with the only difference being that the prepended elements are added at the beginning of the target elements content instead of the end.

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

Sidebar

Related Questions

I am testing the following code with two jQuery versions: 1.5.1 and 1.7.2 $(':radio').change(function(){alert(1)});
I am Just testing this code to stop form by submitting... Jquery Part... $(#request_quote).submit(function(e){
Testing this jquery code on external sites (loaded via proxy to bypass Single Origin
I have a rails backend and am testing the following jquery code against it:
I am currently testing this in Mozilla FireFox 3.0.5 using FireBug 1.3.0 with jQuery
<html> <head> <title>Testing AJAX</title> <script type=text/javascript src=//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js></script> <script> function init() { $(#form1).submit(submitForm); } function
I'm going over the jquery widget here: http://blog.davidpadbury.com/2010/10/11/bdd-testing-of-jquery-plugins-using-jasmine/ The plugin is called like so:
what tools do you use for writing jquery code and testing/debugging your code?
I am testing a website in Firefox 8. I am using a jQuery.post call
I was testing out an interface I built using jQuery UI draggable, droppable and

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.