Reputation: 2881
I've something like:
<div class="the_notice">
<span class="time"> | 3:48pm</span>
To <strong>2013-03-16_10-56-33</strong> By <strong>XYX</strong>
</div>
In a result I want something like:
<div class="the_notice">
<span class="time"> | 3:48pm</span>
<div class="wrap">
To <strong>2013-03-16_10-56-33</strong> By <strong>XYX</strong>
</div>
</div>
How can I achieve this using jQuery? Please help me on that.
Upvotes: 4
Views: 73
Reputation: 10219
With one line (or 3 for clarity):
$('.the_notice')
.wrapInner($('<div class="wrap">'))
.prepend($('.the_notice .time').detach());
Upvotes: 0
Reputation: 55
read this link it may help you :What is the Most effcient way to create html elements using jquery
My Answer is the answer well be like this :
var myTimeIsHere = //calculate your time here;
var x = //calculate x here.;
var y = //calculate y here.;
var newHTML = "<span class='time'>" |+ myTimeIsHere+"</span>"+
"<div class='wrap'>To <strong> "+x+" </strong>"+
"by "+y+"</div>";
$(".the_notice").html(newHTML);
Upvotes: 0
Reputation: 207501
Well if the contents will always be the same, you can do something like
$('.the_notice').contents().slice(2).wrapAll('<div class="wrap"/>');
Upvotes: 4
Reputation: 44740
var temp = $('.time');
$('.time').remove();
$(".the_notice").contents().wrapAll('<div class="wrap" />');
$(".the_notice").prepend(temp);
Upvotes: 0