put div and inside <td> tag
Question by vikas tyagi
it’s dynamic code and i have design issue with that
<td id="test" class="test1"></td>
<div id="WidgetButton" class="right">test</div> // that part of code making dyamic
there is any way put that <div> has id WidgetButton and inside <td></td>
like that
<td id="test" class="test1">
<div id="WidgetButton" class="right">test</div>
</td>
plz suggest me how can i do it with jquery
thanks
Answer by T.J. Crowder
As both of them have id
s, this is a trivial application of the jQuery
function (usually aliased as $
) and appendTo
.
$("#WidgetButton").appendTo("#test");
It’s just as well they both have id
s, too, because otherwise it would be tricky, since the markup is invalid and so browsers will relocate the div
to where they guess it should go, so using structural selectors and relative traversal would be difficult. The id
values trump that, thankfully.
Answer by Starx
Update:
Since you only want to do this for div with id WidgetButton
. Heres how
$("#WidgetButton").appendTo("#test");
If you to remove all divs
and put inside a td
, it might prove to be dangerous. But you can do this like
$("div").each(function() {
$(this).appendTo("#test");
});
However, I will extremely recommend you narrow your selection to a particular group of divs like using class names or ids.
ClassName
$(".divswithclassname").each(function() {
$(this).appendTo("#test");
});
Certain Id
$("#idofdiv")..appendTo("#test");