I want to append div inside mytext div but it is updating text outside of the div
Try like this
$(function(){
var jj= $('body').append('<div class="mytext"></div>');
$('.mytext').html('<div>min</div>') ;
});
jj refers to 'body' element.
$(function () {
var $mydiv = $('<div>min</div>'),
$body = $('body');
$body.append('<div class="mytext">');
var $mytext = $body.find('.mytext:last');
$mytext.append($mydiv);
})
you don't need jj
<head>
<script type="text/javascript" src="jquery-1.8.3.js"></script>
<script type="text/javascript">
$(function(){
$('body').append('<div class="mytext"><div>min</div></div>')
})
</script>
</head>
<body>
</body>
var myDiv = $('<div class="mytext"></div>');
myDiv.append('<div>min</div>');
$('body').append(myDiv);
The append
function doesn't append html to the document. It appends elements to the document object tree.
You could, however, just write this on one line like this, if you wish.
$('body').append('<div class="mytext"><div>min</div></div>');
Boom.
$(function(){
var jj= $('<div class="mytext"></div>');
body.append(jj.append('<div>min</div>'));
});