I am trying to apply to an input.val()
a text
from a span
element but when I try to check it in console
I don't get it.
$("#sandbox-container span").on("click", function(e) {
$("#sandbox-container span").removeClass("selected_year");
$(this).attr("class", "selected_year");
var dateSelected = $(".selected_year").text();
var dateCat = $(".time_value").val(dateSelected);
console.log(dateSelected);
console.log(dateCat);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="sandbox-container">
<span class="selected_year">2014</span>
<span>2018</span>
</div>
<input label="null" style="display: none;" class="time_value" maxlength="99" name="usp-category" type="text" value="">
The above gives me:
2014
(index):208 r.fn.init [prevObject: r.fn.init(1)]
While I would expect console.log(dateCat);
to give me 2014