removeClass JQUERY does not work

1

I'm using ASP.NET to make a form, but I need to remove the class disable , I'm using JQUERY , and I need to remove it to several labels that make up my object, but I'm not having much success.

The objects that I want to affect are

btn-group bootstrap-select disabled form-control has-feedback-left

and

btn dropdown-toggle disabled btn-defaul

function RemoveClass() {

  var selectCon;
  selectCon = $('.btn .dropdown-toggle .disabled .btn-default');
  $(selectCon ).removeClass('.disabled');

}
<div id="selectx">
  <div class="btn-group bootstrap-select disabled form-control has-feedback-left">
    <button type="button" class="btn dropdown-toggle disabled btn-default" data-toggle="dropdown" role="button" data-id="ldClientes" tabindex="-1" aria-disabled="true" title="HYCSA"><span class="filter-option pull-left">HYCSA</span>&nbsp;<span class="bs-caret"><span class="caret"></span></span></button>
    <div class="dropdown-menu open" role="combobox">
      <div class="bs-searchbox"><input type="text" class="form-control" autocomplete="off" placeholder="Buscar" role="textbox" aria-label="Search"></div>
      <!--esto no es relevante-->
      <select id="ldClientes" name="lstClientes" data-c-variable="idCliente" data-c-campobase="true" data-c-ctr="true" data-live-search="true" type="text" class="form-control has-feedback-left" data-p-condatos="true" tabindex="-98" data-c-plugin="selectpicker"
        data-p-temp1="1">
        <!--esto no es relevante-->ni esto
      </select>
    </div>
  </div>
    
asked by E.Rawrdríguez.Ophanim 08.06.2018 в 18:15
source

5 answers

5

When you use the CSS selectors in jQuery, the . indicates that it is a class. But you do not need that point in the removeClass method.

On the other hand, your selector is incorrect, try without spaces between the classes:

function RemoveClass() {

  var selectCon;
  selectCon = $('.btn.dropdown-toggle.disabled.btn-default');
  $(selectx).removeClass('disabled');

}

the reason is because (using a simpler example)

'div .btn' searches for items with class btn that are within of a div

'div.btn' searches for items that are div and that have the class btn

PS: Have you thought about simply adding an id to the element?

    
answered by 08.06.2018 / 18:17
source
1

To select (or filter by) the CSS classes of the same level, you have to remove the space, for example:

 <div class="btn-group bootstrap-select disabled form-control has-feedback-left">

would be .btn-group.bootstrap-select.disabled.form-control.has-feedback-left

 <button type="button" class="btn dropdown-toggle disabled btn-default"

would be .btn.dropdown-toggle.disabled.btn-default

If you put spaces, assume that it is a child, example:

 <div class"padre">
    <p class="hijo tio"><span class="nieto"></span></p>
    <p class="hijo"><span class="nieto"></span></p>

to select the <p> usas .padre .hijo to select the <span> usas .padre .hijo .nieto o .padre .nieto . Also if you are looking for .padre.hijo or .hijo .tio you will not find elements, the first <p> would be .hijo.tio o .padre .tio .

No spaces = same level, with spaces = one level down.

Going back to your example:

 selectCon = $('.btn.dropdown-toggle.disabled.btn-default');

or more generic

 selectCon = $('.btn.disabled');
    
answered by 08.06.2018 в 18:27
1
var $elementos = $(".btn-group.bootstrap-select.disabled.form-control.has-
feedback-left")
$elementos.add(".btn.dropdown-toggle.disabled.btn-
defaul").removeClass("disabled")

You can use .add () to add another object to your variable and remove the disabled class

    
answered by 08.06.2018 в 19:14
0

I recommend in order to always use an id or class to find objects in jquery easier for example id="btnClientes" and thus nothing more serious to put $ ("# btnClients"). removeClass ("disabled")

    
answered by 08.06.2018 в 20:43
-1

There is no point in doing a multi-element selector if you only want to remove the class disabled . Better iterates class disabled of the elements that contain it, others do not matter. I leave you an example

$(function(){

  $(document).on('click', '#btn',function(){
    
    $('.disabled').each(function(){
      $(this).removeClass('disabled');
    });
  
  })

})
.disabled{
  background-color: red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input class="foo bar poo disabled">
<input class="foo  disabled">
<input class="foo poo disabled">
<input class=" bar poo disabled">
<input class="foo bar poo disabled">
<input class=" bar disabled">
<input class="foo bar poo disabled">
<input class="foo bar">
<input class="poo disabled">

<input type="button" id="btn" value="quitar">
    
answered by 08.06.2018 в 18:23