0

I am creating calendar type control with my html application and i have used table format to achive. In this calendar i have added the date attribute to td elements and my dom will like below

<td date="Tue Aug 30 2016" class="current">30</td>
<td date="Mon Aug 29 2016" class="current">29</td>

I have added the date attributes like this to all dates in that month calendar.

I want to use this date attribute with jQuery selector to retrive that particular td element. Also my date attribute value will get from below code

new Date("11/05/2016").toDateString(); // out will like "Sat Nov 05 2016"

I want select the elements some thing like this

$('.current[date=new Date("11/05/2016").toDateString()]')

// here i have set the 11/05/2016 manually but this will get from local storage variable.

Thanks for any suggestion

3 Answers 3

1

You need to concatenate:

$('.current-month[date="'+new Date("11/05/2016").toDateString()+'"]')
Sign up to request clarification or add additional context in comments.

2 Comments

I am getting arror like this. Syntax error, unrecognized expression: .current-month[date=Fri Aug 26 2016]
Glad to help you.
1

As new Date("11/05/2016").toDateString() needs to be executed, You need to concatenate the result in selector

$('.current-month[date="'+new Date("11/05/2016").toDateString()+'"]')

I would recommend you to use data-* prefixed custom attributes to store arbitrary data.

<td data-date="Tue Aug 30 2016" class="current">30</td>

1 Comment

thanks but gettingSyntax error, unrecognized expression: .current-month[date=Fri Aug 26 2016]
0

Here is how I would do it:

  1. Create a function that loops through all td.current elements and compares the date data field with a supplied date.

  2. When there is a match return that element.

    function getDateElement(date_selector) { $('td.current').each(function () { if($(this).data('date') === date_selector) { return $(this); } }); }

    getDateElement('Tue Aug 30 2016');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.