dev1234
dev1234

Reputation: 5706

Checkbox list label text via jQuery

I have a check box list which enables multi select. i need to get the label of each check box instead of the value and do some work. if values are aaa &&& bbb i need to disable them (not allow user to check) and others i want to display as check able.

I have this piece of code written but doesn't work. I think I am missing something.

  $('#ddcl-ddlOutcomeList-ddw input[type=checkbox]').each(function () {
      console.log($(this).html());
   });

ex:

  <div class="ui-dropdownchecklist-item ui-state-default" style="white-space: nowrap;">
  <input type="checkbox" tabindex="0" class="active" id="ddcl-ddlOutcomeList-i0" index="0" value="1444">
  <label for="ddcl-ddlOutcomeList-i0" class="ui-dropdownchecklist-text" style="cursor: default;">No answer</label>
  </div>

 <div class="ui-dropdownchecklist-item ui-state-default" style="white-space: nowrap;">
 <input type="checkbox" tabindex="1" class="active" id="ddcl-ddlOutcomeList-i1" index="0" value="1445">
 <label for="ddcl-ddlOutcomeList-i1" class="ui-dropdownchecklist-text" style="cursor: default;">No answer 2</label>
 </div>

Upvotes: 0

Views: 957

Answers (3)

dev1234
dev1234

Reputation: 5706

Finally i found a way to do it by my self.

           $('#ddcl-ddlOutcomeList-ddw input:checkbox').each( function(e) {
        var  chkBoxVal=$("label[for='" + $(this).attr("id") +"']").text();
        console.log(chkBoxVal);
     });

Upvotes: 0

dfsq
dfsq

Reputation: 193261

If you want to disable checkboxes with No answer option you can try this:

$('label:contains("No answer")').prev(':checkbox').prop('disabled', true);

http://jsfiddle.net/PUJrQ/

Upvotes: 2

PSR
PSR

Reputation: 40318

<input type="checkbox"  id="test"/>
<label for="test">THIS IS LABEL</label>

You can use $("label[for='test']")

Upvotes: 1

Related Questions