[jQuery] Cloning and wrapping question

[jQuery] Cloning and wrapping question


Due to the constraints of the Shopping Cart system I'm working within,
I am trying to
# In one cell within a row, create a new Paragraph object with class
p_options.
# In the next row, there are two dropdown lists. I want to clone them
and put them in the p.p_options.
* Imagine a table that list items (shirts) in your shopping cart. The
first row contains the img, name, price, total.
* The next row contains two dropdown lists: one, say, for color and
the other for size. That cell is directly below the Name cell (so
they correspond).
* I'm trying to "move" the dd lists into the Name cell.
I have succeeded in cloning the dd lists and placing in the correct
cell, but I cannot get them contained correctly.
Here is the code that almost works:
<blockquote><pre>
        var aNames = $("td.cart_name");
        //For each aNames
        for(var i = 0; i<aNames.length; i++){
            //Get the text, add a P (container for options).
            var oText = aNames[i];
            $(oText).html(vText);
            //Rewrite item Name content
            var vId = "p_options_" + i;
            var vText = oText.innerHTML + "<p id='" + vId + "'
class='p_options'>";
            //Get corresponding options
            //Add them to the container
            var vOptStr = "select[name^='" + vIdPrefix + "']";
            $(vOptStr).clone().appendTo(aNames[i]);
            $(aNames[i]).append("");
        }
</pre></blockquote>
This almost works in that the dd list are correctly placed, but the
looping produces more s than there should be.
I also tried this:
<blockquote><pre>
        var aNames = $("td.cart_name");
        //Insert a new object.
        $("td.cart_name").append("<p class='p_options'><!-- -->") ;
        //Find the elements. Select = dd lists.
        var vOptStr = "select[name*='finopt']";
        //Find the p.p_options that I want to put the dd list into.
        var vPoptions = "p[id^='p_options_']";
        var oPoptions = $(vPoptions);
        var oOptStr = $(vOptStr);
        //Put the dd lists into the p.p_options containers.
//        $(vOptStr).clone().appendTo($(vPoptions));
//        $(vPoptions).append($(vOptStr).clone());
        oPoptions.html(oOptStr).clone();
</pre></blockquote>
This one does not work at all. As you can see, I've tried several
variations (and what you see here are only a few!).
Any ideas!
Thanks tons in advance!























































    • Topic Participants

    • ron