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.

4 Answers 4

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/

Sign up to request clarification or add additional context in comments.

Comments

0

Demo

   var temp = $('.time');
   $('.time').remove();
   $(".the_notice").contents().wrapAll('<div class="wrap" />');
   $(".the_notice").prepend(temp);

1 Comment

That doesn't work, you are removing .time and wrapping every single child.
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);

Comments

0

With one line (or 3 for clarity):

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

JSFIDDLE

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.