markzzz
markzzz

Reputation: 47995

jQuery - How to get a single value[]

I have this code :

<div class="trackon" id="<?="trackline1">
    <input type="hidden" name="atloriginal[]" value="1" /></span>
</div>

<div class="trackon" id="<?="trackline2">
    <input type="hidden" name="atloriginal[]" value="2" /></span>
</div>

<div class="trackon" id="<?="trackline3">
    <input type="hidden" name="atloriginal[]" value="3" /></span>
</div>

How can I change the hidden value of trackline2 on "hello"? I'm here :

$('#trackline2').find("DON'T KNOW HOW TO WRITE THIS").val("hello");

is is possible to set that value to an input array?

Upvotes: 0

Views: 110

Answers (2)

amit_g
amit_g

Reputation: 31260

If you have just one input

$('#trackline2 input').val("hello");

If you have more than one, you need to have some way of identifying them. May be using name...

$('#trackline2 input[name="atloriginal[]"]').val("hello");

Upvotes: 3

Billy Moon
Billy Moon

Reputation: 58611

Assuming the trackon class objects are the only ones on the page, and they are always in order, you could use:

$('.trackon').eq(2).val('hello')

Upvotes: 0

Related Questions