javascript - jQuery specify inner html -
javascript - jQuery specify inner html -
i creating jquery div element below;
var divele = $('<div />', {'class': 'editabletxt','data-model-attr':currelmmodelattr,'data-model-id':'currelmmodelid'});
now want append html text/value within div...
so should render as;
<div class="editabletxt" data-model-attr="modelattr" data-model-id="currelmmodelid">my inner html/text</div>
i doing;
$(this).parent().append(divele).append($(this).val());
but renders separate kid element , not within divele...
how specify in same syntax above ?
you should utilize .html()
set html divele
$(this).parent().append(divele.html($(this).val()));
or
simply use
var divele = $('<div />', { 'class': 'editabletxt', 'data-model-attr': currelmmodelattr, 'data-model-id': 'currelmmodelid', 'html' : 'my inner html/text' });
demo
javascript jquery
Comments
Post a Comment