How to call a Selector in Jquery?

1

The problem is that I do not know how to call in jquery selectors that are inside a div in jquery, I need it because in my code to the functions well but when assigning a container to the divs that are called by the query no longer It does all the function of events like removing

<div id="campoBusq"></div>

<div id="cont-categoria" class="centFRH">
    <div id="categoria">';
         include("selectCategJquery.php");  
   </div>
</div>


<script>
        jQuery(document).ready(function() {

            $('#categoria').on('click','.elemento',function() {
               var e = $(this).clone();
               var identificador = $(this).attr("iden");

               if($("#campoBusq").find("."+identificador).length){

               }else{
                 $(e).appendTo('#campoBusq');
               } 
           });

            $('#campoBusq').on('click','.elemento',function() {
               $(this).remove();
            });

        });
  </script>

This is the view

* When I click; he must show in the div that he works as an imput and when he clicks on the content that was added; it is removed but the detail is that before I clicked on the elements of the fieldBusq and the category and removed from where it was assigned that fieldBusq but the one that does not work is categorized since I click and no longer remove this step after assigning new divs as a container *

So goes the New Design

    
asked by Gamez 12.03.2017 в 02:20
source

1 answer

2

That behavior I imagine that at some point was where there is now a blank space

if($("#campoBusq").find("."+identificador).length){
    // Aquí iría el código para remover
} else {
    $(e).appendTo('#campoBusq');
} 

Strictly for a selector to remove an element of its same class within the div #campoBusq would have to be:

if($("#campoBusq").find("."+identificador).length){
    $("#campoBusq").find("."+identificador).remove()
} else {
    $(e).appendTo('#campoBusq');
}
    
answered by 12.03.2017 / 22:49
source