I want to get month and year value from label. How can i get these using jquery?
<label year="2010" month="6" id="current Month"> June 2010</label>
I want to get month and year value from label. How can i get these using jquery?
<label year="2010" month="6" id="current Month"> June 2010</label>
I am changing your id to current-month (having no space)
alert($('#current-month').attr('month'));
alert($('#current-month').attr('year'));
You can use the attr
method. For example, if you have a jQuery object called label
, you could use this code:
console.log(label.attr("year")); // logs the year
console.log(label.attr("month")); // logs the month
Use .attr
$("current_month").attr("month")
$("current_month").attr("year")
And change the labels id to
<label year="2010" month="6" id="current_month"> June 2010</label>
Firstly, I don't think spaces for an id is valid.
So i'd change the id to not include spaces.
<label year="2010" month="6" id="currentMonth"> June 2010</label>
then the jquery code is simple (keep in mind, its better to fetch the jquery object once and use over and over agian)
var label = $('#currentMonth');
var month = label.attr('month');
var year = label.attr('year');
var text = label.text();