JavaScript checkbox not checking via jQuery checkbox checked jquery,checkbox checked jquery event,checkbox checked jquery

I am trying to check the checkbox using Jquery but to no avail. Following is the code.

$(document).ready(function() {
   var url_brand_alias = $("#hidden_brand_alias").val(); //gives a,b
   var url_brand_arr = url_brand_alias.split(',');
   $.each(url_brand_arr, function(key, value) {
       $('input.Brand[rel="'+value+'"]').attr('checked', true);
    });
});

Checkbox html:

<div class="panel-body">
    <div class="form-group">
        <label class="filters-type">
            <input type="checkbox" rel="a" value="1" class="Brand">a</label>
        </div>
    <div class="form-group">
        <label class="filters-type"><input type="checkbox" rel="b" value="2" class="Brand">b</label>
    </div>
</div>

I tried using both attr and prop but to no avail. I have no any error in console also. Any help/suggestions are welcome. Thanks in advance.

Answer:1

Just adding a simple line url_brand_alias = "a,b"; gives the desired result, suggesting $("#hidden_brand_alias").val(); //gives a,b does not in fact return "a,b" as expected. Consider investigating that.

$(document).ready(function() {
   var url_brand_alias = $("#hidden_brand_alias").val(); //gives a,b
   url_brand_alias = "a,b";
   var url_brand_arr = url_brand_alias.split(',');
   $.each(url_brand_arr, function(key, value) {
       $('input.Brand[rel="'+value+'"]').attr('checked', true);
    });
});
<div class="panel-body">
    <div class="form-group">
        <label class="filters-type">
            <input type="checkbox" rel="a" value="1" class="Brand">a
        </label>
    </div>
    <div class="form-group">
        <label class="filters-type">
            <input type="checkbox" rel="b" value="2" class="Brand">b
        </label>
    </div>
</div>
Answer:2

Is there a way to remove the initial vertical line from the chart without removing the values? here is how my options look like: scales: { yAxes: [{ ticks: { ...

Is there a way to remove the initial vertical line from the chart without removing the values? here is how my options look like: scales: { yAxes: [{ ticks: { ...

  1. chart js remove first data
  2. chart js remove first point
  3. chart js remove first vertical line

I want to build a home page for a website project I'm doing with some friend where the whole page will basically be three images one next to the other like so: |1|2|3| --hover--> |1 ||| or --...

I want to build a home page for a website project I'm doing with some friend where the whole page will basically be three images one next to the other like so: |1|2|3| --hover--> |1 ||| or --...

I'm reading up on my Javascript and came across two very different Prototype pattern examples through my readings. Here is the example from Professional JavaScript for Web Developers, 3rd Edition: ...

I'm reading up on my Javascript and came across two very different Prototype pattern examples through my readings. Here is the example from Professional JavaScript for Web Developers, 3rd Edition: ...

I want to write an unit test for a JavaScript function and measure how often a function triggered a reflow in the browser. Given the following example: // Bad example function foo(elements) { for ...

I want to write an unit test for a JavaScript function and measure how often a function triggered a reflow in the browser. Given the following example: // Bad example function foo(elements) { for ...