tags:

views:

30

answers:

3
$('#columnList').append("<li>" + $(colInProcID) + "</li>");

Obviously, Im doing something wrong...not sure how to say the above so that I dont get [object object] in my list.

**Sorry, let me clarify ... the $(colInProcID) is a DIV that I want inserted into the list. (sorry)

+1  A: 
$(colInProcID)

is a jQuery object, not a string. You'll need to specify which of the potentially many matches you want.

EDIT:

Remember that in the browser, while it's true that everything is textual (obviously negating images), what we work with in javascript are objects, such as a div object holding a text span or a paragraph or whatever. So when you grab it with jQuery via a selector, it's now a jQuery object wrapping another object (even if that target object is a string).

So, you have to either remove the reference to the jQuery object (by calling a array reference or what have you) or you have to use direct XHTML/XML/HTML inside your call.

$('#columnList').append("<li>" + $(colInProcID) + "</li>");

into

var stringToInsert = "<div><p>sometext</p></div>";
$('#columnList').append("<li>" + stringToInsert + "</li>");

or perhaps

var stringToInsert = $(colInProcID)[0];
$('#columnList').append("<li>" + stringToInsert + "</li>");

or someone suggested .get(0) which I think works too.

You have to remember the part about anything grabbed with a selector $(colInProcID) or $("#SomeDivToUse") is a jQuery object, not an XML object or a string.

Hope this clarified things just a tad, and helped you out.

drachenstern
Im sorry, that is a DIV that I want inserted...so I want to insert the entire DIV
toddv
Yeah but that's not what you're asking. Lemme edit.
drachenstern
thanks a ton for the info! If I cant get the wrap thing to work, I may just have to build a new string div with a new id I suppose.
toddv
A: 

I think it's:

$( colInProcID ).wrap('li').appendTo('#columnList');

What is colInProcID?

Adam Backstrom
Ahhh.. that kind of works but for some reason I do not see the LI now for that div in the list even though it is in there... weird
toddv
@toddv Are you using Firefox with the Firebug addin? You really should be if you're not so you can diagnose exactly what's happening in realtime. Consider it the jQuery IDE ;) [no, not really, but it sounds nice ~ but definitely install those two items if you haven't!!!!]
drachenstern
Yes, I am ...that is what I meant by not being able to see the LI from the WRAP in firebug. Not sure why, but after doing the above, I just have DIV inside the list but its not wrapped in an LI
toddv
A: 

Here is what I used to get the DIV into the list

$('#columnList').append("<li id='appendedLI'>");
$(colInProcID).appendTo('#appendedLI');

I tried the .wrap function and thought it was going to work but for some reason, the LI never showed up in FF3 or IE7.

toddv