Remove label style from several label that are inside a div (JQuery)

0

As the title says, I want to remove the style tag from the following code by JQuery .

Code:

<div id="action_ligne" class="action_ligne">
    <label class="lbl obligatorio checked" style="color: red;">Code postal</label>
    <label class="obligatorio checked" maxlength="30" id="val_CL_ZIP" style="color: red;">NW8 9AY</label>
</div>

I forgot to clarify that this is inside a very extensive html document so they are not the only label within the Sun

    
asked by Federico Ramos 18.08.2017 в 21:41
source

3 answers

1

I see that both tags share the mandatory class, so from there you can do it like this:

$(document).ready(function(){
  $(".obligatorio").removeAttr("style");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<div id="action_ligne" class="action_ligne">
    <label class="lbl obligatorio checked" style="color: red;">Code postal</label>
    <label class="obligatorio checked" maxlength="30" id="val_CL_ZIP" style="color: red;">NW8 9AY</label>
</div>

They are both label as well, so you can do it like this:

$(document).ready(function(){
  $("label").removeAttr("style");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<div id="action_ligne" class="action_ligne">
    <label class="lbl obligatorio checked" style="color: red;">Code postal</label>
    <label class="obligatorio checked" maxlength="30" id="val_CL_ZIP" style="color: red;">NW8 9AY</label>
</div>

Taking as regerencia the id of the father div:

$(document).ready(function(){
  $("#action_ligne").find("label").each(function(){
    $(this).removeAttr("style");
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
    <div id="action_ligne" class="action_ligne">
        <label class="lbl obligatorio checked" style="color: red;">Code postal</label>
        <label class="obligatorio checked" maxlength="30" id="val_CL_ZIP" style="color: red;">NW8 9AY</label>
    </div>
    
answered by 18.08.2017 в 21:55
1

I would make it that simple:

$('label').removeAttr("style");
    
answered by 18.08.2017 в 22:13
0

Use .removeAttr(attrName) to remove an attribute from an html element:

function eliminarStyle()
{
 $("#action_ligne label:last").removeAttr("style");
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="action_ligne" class="action_ligne">
    <label class="lbl obligatorio checked" style="color: red;">Code postal</label>
    <label class="obligatorio checked" maxlength="30" id="val_CL_ZIP" style="color: red;">NW8 9AY</label>
</div>

<button onclick="eliminarStyle()">Eliminar style</button>
    
answered by 18.08.2017 в 21:53