0

I have collection of div in my Application. One of functionality I want to implement is Date Filter. It looks like this:

var iExamDate = new Date(aData[9]);
var startDate = new Date($('#start-datepicker-min').val());
var endDate = new Date($('#end-datepicker-max').val());
iExamDateMatch = (startDate <= iExamDate && endDate >= iExamDate);
return iExamDateMatch;

From Firefox Debugger:

aData[9] = <div id="Exmdt_1" shortdate="11/3/2011" longdate="12:00:00" am="">11/3/2011</div>

When I checked iExamDate I saw NaN of course, because I've tried to create new Date from whole div

How should I create iExamdate in order to get Date correct. Any help, please. Thanks

tereško
  • 58,060
  • 25
  • 98
  • 150
Bryuk
  • 3,295
  • 10
  • 45
  • 74
  • 1
    As an aside, based on the HTML you are showing it is invalid because of the attributes you are adding. If you are targeting HTML5 you should be pre-pending those with 'data-'. See this answer http://stackoverflow.com/a/1735268/603520 – Jared Oct 12 '13 at 18:21

3 Answers3

1

You can use jQuery's .text() function to get the text within the <div>. However, I see you are also storing the date in an attribute, so you could use the getAttribute() function, also. Keep in mind, these must be used with jQuery, so it will depend on what aData[9] is. Is it a string containing the HTML of the div? Or is it the jQuery object for the div itself?

Joseph
  • 12,678
  • 19
  • 76
  • 115
  • Thanks. I accepted the second answer, because that's exactly what I need, but your answer more information. – Bryuk Oct 12 '13 at 19:41
1

Or $(aData[9]).attr("shortdate")

Shane
  • 875
  • 1
  • 6
  • 24
0

You can use getAttribute() method to achieve this.

aData[9].getAttribute('shortdate');

Or if you want to get value from inside of div use innerHTML

aData[9].innerHTML;
Elon Than
  • 9,603
  • 4
  • 27
  • 37