Reputation: 3253
i have a set of div's
<div id="foo">foo</div>
<div id="q"></div>
<div id="bar">bar</div>
<div id="tags">tags</div>
i need to remove <div id="tags">tags</div>
and append it to <div id="q"></div>
when the page is loaded using jquery.
i tried the below but doesnt work
jQuery(function ($) {
$( '#tags' ).ready(function() {
$('#q').append(this);
});
});
instead of ready if y try click it works but i need to show it when the page is loaded
any help will be appreciated
Upvotes: 0
Views: 1039
Reputation: 85
$( document ).ready(function() {
var ele= $('#tags').html();
$('#tags').remove();
$('#q').append(ele);
});
Upvotes: 0
Reputation: 28513
Try this : You can use appendTo()
or append()
as shown below
1) appendTo()
$(function() {
$('#tags').appendTo('#q');
});
2) append()
$(function() {
$('#q').append($('#tags'));
});
NOTE - make sure that id
s of the elements are unique through out the DOM
Upvotes: 2