0

I am trying to hide a div class field using j query and i am unable to do so. It is a ticket field in a support form. That needs to be hidden at the beginning and reflect when a particular value is selected. I does not work. I have tried it two different ways and it does not work. Below is the HTML Code, HTML Image and the JQuery Code that i have used.

HTML:

<div class="form-field string optional request_custom_fields_21158635">
  <label for="request_custom_fields_21158635">iOS Plugin Details</label>
  <input id="request_custom_fields_21158635" type="text" name="request[custom_fields][21158635]">
  <p>Please provide the iOS Plugin version details for your request. Example: iOS GA5.0.38</p>
</div>

J Query Code: One Hides only field and label remains visible.

var iosPluginId = "21158635";
$(document).ready(function() {
  if(cust_tags == "kony_internal") {
    $('#request_custom_fields_'+iosPluginId).hide();
  }
});

JQuery Code: Two Both the label and field are visible.

$(".form-field string optional request_custom_fields_21158635").hide();

HTML Image

Renato Lyke
  • 43
  • 10
  • What is the value of `cust_tags`? Also you have syntax error *document ready* handler is not closed properly. Also try `$(".form-field.string.optional.request_custom_fields_21158635").hide();` – Satpal Dec 23 '14 at 05:46
  • its better to provide a unique class name for the div and call the hide().$(".myclass").hide(); also provide myclass class for that div element – AVM Dec 23 '14 at 05:49
  • selector you are using is looking for a tagname, not a class – charlietfl Dec 23 '14 at 05:50
  • Hi, The user when he clicks on submit a form, Will take him to the form page. Under Category option. If the user selects iPhone then this field needs to be displayed. Otherwise it needs to be hidden. – Renato Lyke Dec 23 '14 at 05:54
  • I think, if condition is not getting satisfied because $('#request_custom_fields_'+iosPluginId).hide(); this is proper code to hide the element – Domain Dec 23 '14 at 05:54

2 Answers2

1

You are using multiple selectors, if you can use them together like

$(".form-field.string.optional.request_custom_fields_21158635").hide();

it will be intersection, it means select element which have all of the classes. Or if you want a union, you can use

$(".form-field, .string.optional, .request_custom_fields_21158635").hide();

which means select element which have atleast one class

Related question : How can I select an element with multiple classes?

Fiddle

Community
  • 1
  • 1
Ajinkya
  • 22,324
  • 33
  • 110
  • 161
1

you can try below code. It will work.

$('#request_custom_fields_'+iosPluginId).hide();
change this to below code.

you cannot use # for class. You have to use "." for class and "#" for id.

   $('.request_custom_fields_'+iosPluginId).hide();
Ajinkya
  • 22,324
  • 33
  • 110
  • 161
Sameeraa4ever
  • 568
  • 7
  • 20