Q:

use jQuery to hide div with if statement and addClass

I have a div generated through a plugin that I want to hide when disabled=true. After reading through the posts on SO, I thought maybe I could use .attr to find the disabled=true and then addClass to hide it with CSS display: none. I can't edit the plug-in or source code, so I'm hoping I can do this from the front end through our CMS. I'm a jQuery beginner so maybe this isn't possible?
I want to hide the disabled arrows in the carousel at the bottom of this page.  The HTML looks like this after it is generated by the plugin:
        <div class="jcarousel-prev jcarousel-prev-horizontal jcarousel-prev-disabled jcarousel-prev-disabled-horizontal" style="display: block;" disabled="true"></div>

and I have added this code to the CMS but it's not working. I don't see any errors in the console; is this the right approach? Is there something wrong with my syntax?
        if ($('div.jcarousel-prev.jcarousel-prev-horizontal.jcarousel-prev-disabled.jcarousel-prev-disabled-horizontal').attr('disabled', true)){
            $(this).addClass("arrow");
        }

Thanks in advance for any help.

A:

The :disabled selector won't work with any element but a form field. It is perhaps a bit non-standard to be using it on anything but forms; it is even more non-standard to use the value of "true," which should instead also be "disabled" (see Correct value for disabled attribute). So instead of using :disabled, your code as written would need to use the selector [disabled="true"].
Your selector probably doesn't need to use the entire list of classes -- the last class on the list is probably all you need to target.
However, I would simply use CSS for what you are trying to do. Instead of having the arrow class in your stylesheet, replace it with .jcarousel-prev-disabled-horizontal.
If you still wanted to go the "disabled" route though with JavaScript, use the following, which will also replace the need for an if-statement:
$('.jcarousel-prev-disabled-horizontal[disabled="true"]').addClass('arrow');

