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?

2 Answers 2

2

CSS:

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

jQuery:

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

Here is a demo.

Sign up to request clarification or add additional context in comments.

2 Comments

var getDate = $(".datepicker").val(); var getMark = $('li > span + input').val(); var plusVal = getDate + getMark; $(".picker").val(plusVal); alert(plusVal);
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?"
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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.