Get first value before comma

2

Hello, I'm having trouble storing the value of the day before the comma:

<span id="organizerContainer-date">Novembro 3, 2018</span>

I would like to store this value to do some things. If anyone has done this before could you let me know what it would be like to do this using jquery?

    
asked by anonymous 03.11.2017 / 21:20

2 answers

0

Using jQuery:

dia_ = $('#organizerContainer-date').text().split(' ')[1].replace(/\D/g, '');
console.log(dia_); // retorna 3
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><spanid="organizerContainer-date">Novembro 3, 2018</span>
    
03.11.2017 / 21:33
3

You do not need jQuery for this, with JavaScript being simple and you can do so, assuming that the date format is always the same:

var span = document.getElementById("organizerContainer-date");
var nr = span.innerHTML.split(/[\s,]/).filter(Boolean)[1];
console.log(nr); // 3
<span id="organizerContainer-date">Novembro 3, 2018</span>
    
03.11.2017 / 21:25