简体   繁体   中英

How can get the text enclosed by a span tag and save it to a hidden input value when I click the span?

I need to put the text enclosed by a span tag in my hidden input when I click that span tag.

This is my code I have:

<tr class="vevnumdays">
<td class="vevfree" align="center"><span class="vevmonthday">15</span></td>
<td class="vevfree" align="center"><span class="vevmonthday">16</span></td>
<td class="vevfree" align="center"><span class="vevmonthday">17</span></td>
</tr>
<input name="startdate" id="startdate" type="hidden" class="sv_date_box" value="Select a Date"/> 

How can do it using jquery click?

Try this

$('.vevmonthday').click(function()
{
    $("#startdate").val($(this).text());
});

Example : https://jsfiddle.net/xjekbv13/

This should work - https://jsfiddle.net/ToddNewent/z4cd04tj/

$('.vevmonthday').on('click',function(){
    $('#startdate').val($(this).text());
});

It takes the inner text of the span .vevmonthday and sets the #startdate to that value.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM