Multiple Elements in .html ()

I have objects: object S and oject SD.

//form group startTime
formStart = $(fstart).clone();
s = $(d).clone();
    $(s).addClass('input-group date datetimepicker-s').html(startTime);

sd = $(d).clone();
    $(sd).addClass('input-group date datetimepicker-s').html(startDate);

And I want to put them in one group as follows:

$(formStart).html(s,sd).prepend('<label>Begintijd</label>');

But maybe it is very obvious, it does not work. My question is whether it is possible to add multiple elements in .html () or can I do this:

$(element).html().html();
+4
source share
2 answers

You should not use .html()at all when you want to pass jQuery objects. Instead, use one that takes an array of elements or a variable number of arguments: .append()

formStart.append(s, sd)

If you want to clear the parent element first (repeat the behavior .html()), use (what a surprise): .empty()

formStart.empty().append(s, sd)

, .clone jQuery, formstart jQuery, formstart $(formStart). s sd. jQuery, jQuery: https://learn.jquery.com/.

+10

.append()

$(formStart).append(s,sd)

append() ,

$(formStart).empty().append(s,sd)
+4

Source: https://habr.com/ru/post/1540341/


All Articles