Dilini Wasana
Dilini Wasana

Reputation: 267

how to select a input using jquery

My html is look like below (it's not a html I'm echoing this using PHP. And it has lot of <li></li> with same 3 inputs content. It's a dynamically generated one)

<li><span class='add-on'></span>" .
    "<input class='' type='text' value='' />
    <input class='picker' type='hidden' value='' name=''  />
    <input class='datepicker' type='text' />
</li>

I want to select first input using CSS. I tried first-child but no luck.we can't put any class or Id to that first input. Because I was write another JS script to find non class inputs. So I want to select that first input using jQuery. And I need to put that first input value and datepicker class value to hidden input value. I was try following script. But I don't know how to select that input using jQuery.

jQuery

var getDate = $(".datepicker").val();
var getMark = $("I want to any select to select first input").val();
var plusVal = getDate + getMark;

$(".picker").val(plusVal);

How to do it?

Upvotes: 0

Views: 87

Answers (2)

Linus Caldwell
Linus Caldwell

Reputation: 11078

CSS:

li > span + input { /* styles here */ }

jQuery:

$('li > span + input').val();

Here is a demo.

Upvotes: 2

Jake
Jake

Reputation: 4234

If you can depend on CSS3, then you can use li > input:first-of-type or li > input:nth-of-type:(1). Otherwise you could use li > span + input

Upvotes: 0

Related Questions