I have the next html.
I need to get a span text content of 'Jan' and '2017' in a onclick function.
I can´t use contains('Jan') or contains('2017') because that values can change at runtime.
I tried the next but no success.
div.relative {
position: relative;
top: 30px;
right: 30px;
bottom: 30px;
left: 30px;
border: 3px solid #73AD21;
}
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script>
function ClockClicked(){
var smonth=$("span.spanmonth").filter(function() { return ($(this).text()) });
var syear=$("span.spanyear").filter(function() { return ($(this).text()) });
alert(smonth+'-'+ syear);
};
</script>
</head>
<body>
<div class="myclock">
<div class="controls">
<a class="pull-left">
<div class="btn btn-primary" onclick="ClockClicked()">Click me</div>
</a>
<h4>
<span class="spanmonth" Jan></span> - <span class="spanyear" 2017></span>
</h4>
</div>
</div>
</body>
</html>
html:
I have used this function:
. I only did changes to my needs. I add onclick and a class to my needs. No other changes.