4

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.

The System Restart
  • 2,873
  • 19
  • 28

4 Answers4

4

Well if the contents will always be the same, you can do something like

$('.the_notice').contents().slice(2).wrapAll('<div class="wrap"/>');

http://jsfiddle.net/Ysq48/

epascarello
  • 204,599
  • 20
  • 195
  • 236
0

Demo

   var temp = $('.time');
   $('.time').remove();
   $(".the_notice").contents().wrapAll('<div class="wrap" />');
   $(".the_notice").prepend(temp);
Adil Shaikh
  • 44,509
  • 17
  • 89
  • 111
0

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);
Community
  • 1
  • 1
abu taha9
  • 45
  • 14
0

With one line (or 3 for clarity):

$('.the_notice')
     .wrapInner($('<div class="wrap">'))
     .prepend($('.the_notice .time').detach());

JSFIDDLE

Shikiryu
  • 10,180
  • 8
  • 49
  • 75