Richard77
Richard77

Reputation: 21621

Select checkbox by class and make the text inside bold

After an ajax call, this is how the div is populated with a list of pair (checkbox, name).

$.each(data, function(i, item) {
     $('#userListCheckBox').append(
       '<input type="checkbox" class="cbUser ' + item.IsApproved + 
       '" value="cb_' + item.UserId + '">' +
       item.FirstName + ' ' + item.LastName + '</input><br/>'
      );
    });

Before only approved users could be displayed. Now every user will be displayed. The only difference is that I want to display inactive user in bold. That's why I added the value of the item.IsApproved to the list of classes.

I'm trying to make bold the text inside the checkbox, using the following code.

$('#userListCheckBox :checkbox .false').html().css('font-weight', 'bold');

but it's not working.

Upvotes: 0

Views: 670

Answers (1)

tymeJV
tymeJV

Reputation: 104775

You have an extra space in your selector:

$('#userListCheckBox :checkbox.false').next("label").css('font-weight', 'bold');

Also, input should be self-closing, you should wrap the text in a label and target that.

$('#userListCheckBox').append(
   '<label><input type="checkbox" class="cbUser ' + item.IsApproved + 
   '" value="cb_' + item.UserId + '"/>' +
   item.FirstName + ' ' + item.LastName + '</label><br/>'
  );
});

Upvotes: 2

Related Questions