将jquery元素转换为html

时间:2015-08-13 21:33:18

标签: javascript jquery html

我试图给这个按钮一个div包装器。我怎么做?如果我需要将其转换为html来执行此操作,那么最有效的方法是什么?谢谢

var button = ($('<button>', {
            "id": "jspsych-free-sort-done-btn",
            "class": "jspsych-free-sort",
            "html": "Done",
            "style": "text-align:center",
            "click": function() {
                var end_time = (new Date()).getTime();
                var rt = end_time - start_time;
                // gather data
                // get final position of all objects
                var final_locations = [];
                $('.jspsych-free-sort-draggable').each(function() {
                    final_locations.push({
                        "src": $(this).attr('src'),
                        "x": $(this).css('left'),
                        "y": $(this).css('top')
                    });
                });

                jsPsych.data.write({
                    "init_locations": JSON.stringify(init_locations),
                    "moves": JSON.stringify(moves),
                    "final_locations": JSON.stringify(final_locations),
                    "rt": rt
                });

                // advance to next part
                display_element.html("");
                jsPsych.finishTrial();
            }
        }));

1 个答案:

答案 0 :(得分:1)

jQuery Wrap

  

描述:围绕匹配元素集中的每个元素包装HTML结构。

button.wrap('<div></div>');