How to duplicate an image selection

Asked

Viewed 65 times

-2

I need to create more of a pointer like the same image q is in css as I do this??

ponteiro = document.querySelector("#ponteiro");
#ponteiro{
	background-image: url("../img/ponteiro.png");
}
<div id="ponteiro"></div>

  • What’s the matter?

  • I want to create more than one image, the same as the pointer.. Creating a new div? and assigning a new name to id?? <div id="pointer"></div> <div id="pointer 1"></div> for(blablabla) pointer = Document.querySelectorAll("#pointer" + i);

  • Could you explain your problem better? I still don’t understand

1 answer

2


You can clone your div, but this would duplicate the id (which is not recommended). Then using the class attribute you can select the original div and clone the element, if you need to assign an id to the new element I can add this treatment in the answer.

$(document).ready(function(){
  var ponteiro =  $(".ponteiro:first");
  $("#btnClone").on('click', function(){
      $('body').append($(ponteiro).clone(true));
  });
});
.ponteiro{
  position:relative;
	background-image: url("../img/ponteiro.png");
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="button" id="btnClone" value="clonar" />
<div class="ponteiro">texto para visualização do exemplo</div>

Browser other questions tagged

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