0

Very similar to this, however, in my case, the value of the label can change. I am trying to make the font change on click. here is what I have thus far :

    // Job Type Button
    $('fieldset.workexperience input').on('change', function() {
        if ($(this).hasClass('jobtype') && ($(this).attr("name")!="")) {
            $('.'+$(this).attr("name")).toggle("slow");
            //Change color to white to show hidden
                $('label[for=$(this)]').toggleClass("hidden");

                $(this).toggleClass("hidden");

                var $this = $(this).attr("label");
                $('label[$this]').toggleClass("hidden");
        } else {

        }
    });

There are three attempts, the first to access it by its label, the second to directly access it (but $(this) is the checkbox, not the label), and the second is to try to get the value of the label, then pass it in as an argument.

Any help would be greatly appreciated.

BTW: CSS is :

    .hidden {
    color: white;
    }
Community
  • 1
  • 1
chris Frisina
  • 19,086
  • 22
  • 87
  • 167

1 Answers1

2
$('label[for=$(this)]').toggleClass("hidden");

should

$('label[for="'+ $(this).attr('id') +'"]').toggleClass("hidden");

For example:

<label for="somecheckbox">Checkbox</label>
<input type="checkbox" id="somecheckbox">

So $(this).attr('id') will get the id, which is equal to label's for attribute.

thecodeparadox
  • 86,271
  • 21
  • 138
  • 164