We help IT Professionals succeed at work.
Get Started

jquery clone object and insert into variable before inserting back to dom

1,125 Views
Last Modified: 2012-05-12
Hi guys

i am trying to copy a input box and clone it into the box variable. and then insert it into my newObject variable before putting in into the dom again. but how do i do that? when i do it like i have done in my example it just writes..

[object object]. i need it to be executed of course.
$(this).each(function(){
        var inputWidth = $(this).width();
        var box = $(this).clone();
        
        var newObject = "<div style='float:left;'>"
                      + "<div style='float:left;background:url("+options.leftImage+") 0px 0px no-repeat;height:"+rightImage.height+"px;width:"+rightImage.width+"px;'></div>"
                      + "<div class='inputContainer' style='float:left;background:url("+options.middleImage+") 0px 0px repeat-x;height:"+middleImage.height+"px;width:"+inputWidth+"px;'>"
                      + box
                      + "</div>"
                      + "<div style='float:left;background:url("+options.rightImage+") 0px 0px no-repeat;height:"+rightImage.height+"px;width:"+rightImage.width+"px;'></div>"
                      + "</div><br>";
        
        
        $(this).replaceWith(newObject);
        
    });

Open in new window

Comment
Watch Question
This problem has been solved!
Unlock 1 Answer and 12 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE