Shawn
Shawn

Reputation: 3159

jquery target input with name in last div of class

I have several div's with the class .agrRow. In each .agrRow there is an input field with the name agrNameOF.

I want to set the value of that field. I've tried something like:

$(".agrRow:last input[type='input'][name='agrNameOF']").val(fname);

but that doesn't work.

What is the correct syntax?

Upvotes: 3

Views: 81

Answers (2)

altdovydas
altdovydas

Reputation: 109

Try:

$('.agrRow input[type="text"][name="agrNameOF"]').val(fname);

why you use :last?

Upvotes: 1

mikelt21
mikelt21

Reputation: 2768

try changing input[type='input'] to input[type='text'] or if it can be other types too then just do input[name='agrNameOF']

JSFiddle: http://jsfiddle.net/6tf6fbcn/

Upvotes: 3

Related Questions