How to mark a specific item in a CheckBoxList with jquery

0

I have seen several examples of how to mark and unmark all, but I have not seen how to mark a specific, see:

<asp:CheckBoxList ID="ChkAcoesListarGrupo" runat="server" RepeatDirection="Horizontal" Width="100%" >
                                <asp:ListItem Value="1">Novo</asp:ListItem>
                                <asp:ListItem Value="2">Atualizar</asp:ListItem>
                                <asp:ListItem Value="3">Excluir</asp:ListItem>
                                <asp:ListItem Value="4">Visualizar</asp:ListItem>
                                <asp:ListItem Value="5">Pesquisar</asp:ListItem>
                            </asp:CheckBoxList>

How do I make the item Visualizar checked with jquery ?

It would look something like this:

$('#<%= ddlPerfil.ClientID %>').change(function (e) {
                e.preventDefault();
//Aqui eu marcaria o item **Visualizar**
});
    
asked by anonymous 21.12.2018 / 13:57

1 answer

1

With jQuery you can check a% of% of this way checkbox , using the value attribute .prop('checked', true)

See the example working.

$("#btn").click(function() {
    $('[value="teste"]').prop('checked', true);
});
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script><divid="btn">clicar</div>

<input type="checkbox" name="" id="teste" value="teste">

<p>vc tb pode deixar marcado direto no load, <i>"$(document).ready(function(){ "</i></p>

Via HTML

I do not know if this is exactly what you need but why not use the $('[value="teste"]') html attribute? link

See this example:

<div class="btns">
  <input type="checkbox" name="" id="">item 1<br>
  <input checked type="checkbox" name="" id="">checado<br>
  <input type="checkbox" name="" id="">item 3<br>
  <input type="checkbox" name="" id="">item 4<br>
</div>
    
21.12.2018 / 14:38