简体   繁体   中英

Converting jquery element to html

I am trying to give this button a div wrapper. How do I do that? And if I need to convert it to html to do this what is the most efficient way? Thanks

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();
            }
        }));

jQuery Wrap

Description: Wrap an HTML structure around each element in the set of matched elements.

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

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