Append data-slb-group="slb"

Asked

Viewed 23 times

2

I have several images and I’m trying to use the AppendTo jquery, but I’m not getting

<a href="image1.jpg" data-slb-active="1" data-slb-asset="1947037253" data-slb-internal="0" 
data-slb-group="slb">
            <img class="alignnone size-medium wp-image-527" src="image1.jpg" alt="" 
            width="300" height="225" srcset="image1.jpg" sizes="(max-width: 300px) 100vw, 
           300px">
        </a>   
        <a href="image2.jpg" data-slb-active="1" data-slb-asset="1947037253" 
data-slb-internal="0" data-slb-group="slb">
            <img class="alignnone size-medium wp-image-527" src="image2.jpg" alt="" 
            width="300" height="225" srcset="image2.jpg" sizes="(max-width: 300px) 100vw, 
           300px">
        </a>
        <a href="image3.jpg" data-slb-active="1" data-slb-asset="1947037253"
 data-slb-internal="0" data-slb-group="slb">
            <img class="alignnone size-medium wp-image-527" src="image3.jpg" alt="" 
            width="300" height="225" srcset="image3.jpg" sizes="(max-width: 300px) 100vw, 
           300px">
        </a>

    <div class="images"></div>

the code below works

$('.size-medium').appendTo('.images');

But go to the <div class="images"></div> all images with class .size-medium, without the links <a>

I tried it in many ways but I haven’t yet:

$('a data-slb-group').appendTo('.images');

I appreciate help

  • You want to put those <a> and <img> inside .images, that’s it?

  • Yeah, that’s right, that’s right

1 answer

1


Once the images are inside <a> you can use the selector a[data-slb-active] and then .appendTo('.images'); thus:

$('a[data-slb-active]').appendTo('.images');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a href="image1.jpg" data-slb-active="1" data-slb-asset="1947037253" data-slb-internal="0" data-slb-group="slb">
  <img class="alignnone size-medium wp-image-527" src="image1.jpg" alt="" width="300" height="225" srcset="image1.jpg" sizes="(max-width: 300px) 100vw, 
           300px">
</a>
<a href="image2.jpg" data-slb-active="1" data-slb-asset="1947037253" data-slb-internal="0" data-slb-group="slb">
  <img class="alignnone size-medium wp-image-527" src="image2.jpg" alt="" width="300" height="225" srcset="image2.jpg" sizes="(max-width: 300px) 100vw, 
           300px">
</a>
<a href="image3.jpg" data-slb-active="1" data-slb-asset="1947037253" data-slb-internal="0" data-slb-group="slb">
  <img class="alignnone size-medium wp-image-527" src="image3.jpg" alt="" width="300" height="225" srcset="image3.jpg" sizes="(max-width: 300px) 100vw, 
           300px">
</a>

<div class="images"></div>

That will give:

inserir a descrição da imagem aqui

Browser other questions tagged

You are not signed in. Login or sign up in order to post.