Danny
Danny

Reputation: 107

Jquery selector is getting null

i am rather new to jquery and i am trying to do the below code

 var entityType = $('.unit-edit-entity_type input', self.$rowInEdit).val();
 var parentType = $('.unit-edit-parent_id select', self.$rowInEdit).val();
 $('.unit-edit-entity_type', self.$editEmptyForm).val(entityType);
 $('.unit-edit-parent_id', self.$editEmptyForm).val(parentType);

the var is getting the right value but after creating the jquery value using the class and set the value from the var the result is ''

I cant figure out why. Thank to all.

Upvotes: 0

Views: 72

Answers (3)

Santiago Rebella
Santiago Rebella

Reputation: 2449

I think that if self.$editEmptyForm is an element you should be doing;

$('.unit-edit-entity_type, ' + self.$editEmptyForm).val(entityType);
$('.unit-edit-parent_id, ' + self.$editEmptyForm).val(parentType);

Upvotes: 0

Henk Jansen
Henk Jansen

Reputation: 1142

 $('unit-edit-entity_type', self.$editEmptyForm).val(entityType);
 $('unit-edit-parent_id', self.$editEmptyForm).val(parentType);

Should be

 $('.unit-edit-entity_type', self.$editEmptyForm).val(entityType);
 $('.unit-edit-parent_id', self.$editEmptyForm).val(parentType);

You forgot a .

Upvotes: 3

Murali Murugesan
Murali Murugesan

Reputation: 22619

Prefix . for Class Selector (“.class”)

Change

$('unit-edit-entity_type', self.$editEmptyForm).val(entityType);
 $('unit-edit-parent_id', self.$editEmptyForm).al(parentType);

To

$('.unit-edit-entity_type', self.$editEmptyForm).val(entityType);
 $('.unit-edit-parent_id', self.$editEmptyForm).val(parentType);

Upvotes: 1

Related Questions