toast
toast

Reputation: 670

jQuery Move div into another div

I need to move .link-field-first-ticket-button inside .event-location-one

here's the fiddle: http://jsfiddle.net/ksV73/

It's a cms so I have no choice in the matter.

this is what I'm trying, it's not doing much of anything

$(".widget-upcoming-events-blog li").each( function() {
     var links = $(this).children(".link-field-first-ticket-button").html();
     $(this).children(".link-field-first-ticket-button").html("");
     $(this).children(".event-location-one").append(links);
});

Upvotes: 10

Views: 57786

Answers (6)

ponciste
ponciste

Reputation: 2229

try this

$(".widget-upcoming-events-blog li").each( function() {
     var links = $(".link-field-first-ticket-button").html();
     $(".link-field-first-ticket-button").html("");
     $(".event-location-one").append(links);
});

Upvotes: 2

Guffa
Guffa

Reputation: 700730

The html method will give you the content inside the element, not the element itself.

Just append the element where you want it. As an element can't exist in two places at once, it will be moved:

$(".widget-upcoming-events-blog li").each( function() {
  var links = $(this).children(".link-field-first-ticket-button");
  $(this).children(".event-location-one").append(links);
});

Upvotes: 2

Ricky Stam
Ricky Stam

Reputation: 2126

You can just do this:

$(".link-field-first-ticket-button").appendTo(".event-location-one");

It will move the first ticket button to event location

Upvotes: 36

André Muniz
André Muniz

Reputation: 708

How about use the .appendTo() function?

For example:

$(".widget-upcoming-events-blog li").each( function() {
 $(this).find(".link-field-first-ticket-button")
        .appendTo( $(this).find(".event-location-one") );
});

Upvotes: 1

Oskar Skuteli
Oskar Skuteli

Reputation: 658

x = $(".widget-upcoming-events-blog").find(".link-field-first-ticket-button").remove()
$(".event-location-one").append(x);

Upvotes: 2

Andy Holmes
Andy Holmes

Reputation: 8087

Change your .children() to .find()

$(".widget-upcoming-events-blog li").each( function() {
     var links = $(this).find(".link-field-first-ticket-button").html();
     $(this).find(".link-field-first-ticket-button").html("");
     $(this).find(".event-location-one").append(links);
});

Upvotes: 1

Related Questions