0

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?

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Dilini Wasana
  • 267
  • 1
  • 3
  • 11

2 Answers2

2

CSS:

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

jQuery:

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

Here is a demo.

Linus Caldwell
  • 10,908
  • 12
  • 46
  • 58
  • var getDate = $(".datepicker").val(); var getMark = $('li > span + input').val(); var plusVal = getDate + getMark; $(".picker").val(plusVal); alert(plusVal); – Dilini Wasana May 21 '13 at 15:44
  • Your question was answered. How to cast to datetime would be another question. Maybe something like "[How can I convert string to datetime with format specification in JavaScript?](http://stackoverflow.com/questions/476105/how-can-i-convert-string-to-datetime-with-format-specification-in-javascript)" – Linus Caldwell May 21 '13 at 15:48
0

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

Jake
  • 4,014
  • 8
  • 36
  • 54