0

I want to add additional CSS classes to webform component description field.

in default mode, this item is wrapped inside a div element with "description" class like below:

<div class="description">here is description text</div>

Now I want to add extra CSS classes beside description.

How can I do this? via a module and form alter operation or via theme functions hook?

Please guide me.

1

you can do this by using jquery on ready do this something like

jQuery(document).ready(function() {
         jQuery('#YOUR_FORM_ID .description').addClass('new-desc-class');
}); 

  • I know this solution but it is not useful when javascript is disabled on browser. – Mehrdad201 Dec 20 '13 at 10:02
0

Looks like you are looking for webform classes module:

A simple, small add-in that adds an editable class against each webform component to the webforms module.

Then, in your CSS use .class-on-form-element .description instead of .class-on-description - one word more, but works just as well.

  • Does it add class to description too ? – Mehrdad201 Dec 19 '13 at 18:55
  • @Mehrdad201 Not sure what description is, in Form API terms. If #description then no, as Drupal can't do it in the first place. No hooks / attributes for it. For code solution, see how I hacked it here and here. Code from these answers + code from module above will give you a kickstart. Or simply add class to element and then in css use .element's class .description – Mołot Dec 19 '13 at 19:00
  • Dear @Mołot I tested it, It doesn't add the class description, it is add the class to the element. I am studying your mentioned URLs. but I want to add only some extra CSS to the description element and I think there must be a solution for it without a large number of code lines. I am still searching. I think description must have #prefix and #suffix and I want to find how can I change it's rendering style. – Mehrdad201 Dec 19 '13 at 19:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.