简体   繁体   中英

Appending to a div in JQuery

At first imgButton is a string of text containing HTML for an img tag. However, this variable is later turned into the results of .detach() of the img tag. The problem in the below code is that it does not display the image that it did previously, but instead [object Object] is displayed. It does display the correct image when using imgButton inside of its own append statement or appendTo. Is there a way to print out imgButton in the same append statement as the other strings and have it display properly?

I hope I explained the problem properly.

$("#search_prams").append("<div class='advsearchparam'><select class='searchparam'>" +
        "<option value='test'>test</option>" +
        "<option value='test1'>test1</option>" +
        "</select><input class='search' type='text'><button class='remove' id='remove1'>X</button></div>"+ imgButton);

If it says that imgButton is an object then it is not a string try this,

$("#search_prams").append("your div string here ")
                  .append(imgButton);// append img button here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM