0

I have several pages that has the following mark-up in it, but the value of the datetime attribute is on each page different.

<a class="index" href="#">

    <time datetime="2015-W01">

        <strong>week</strong>
        <strong>01</strong>
        <strong>2015</strong>

    </time>

</a>

On each page I include with PHP at the bottom a page with the following mark-up:

<ul class="weeks">

    <li>

        <a class="ajax" href="<?php echo _LINK_PATH;?>tracks-sets-03-2015">

            <time datetime="2015-W03">

                <strong>week</strong>
                <strong>03</strong>
                <strong>2015</strong>

            </time>

            <ol>

                <li>artist 01</li>
                <li>artist 02</li>
                <li>artist 03</li>
                <li>artist 04</li>
                <li>artist 05</li>

            </ol>

        </a>

    </li>
    <li>

        <a class="ajax" href="<?php echo _LINK_PATH;?>tracks-sets-02-2015">

            <time datetime="2015-W02">

                <strong>week</strong>
                <strong>02</strong>
                <strong>2015</strong>

            </time>

            <ol>

                <li>Hill Classics</li>
                <li>Colman Brothers</li>
                <li>Vicktor Taiwò</li>
                <li>Leftside Wobble</li>
                <li>Mo Kolours</li>

            </ol>

        </a>

    </li>
    <li>

        <a class="ajax" href="<?php echo _LINK_PATH;?>tracks-sets-01-2015">

            <time datetime="2015-W01">

                <strong>week</strong>
                <strong>01</strong>
                <strong>2015</strong>

            </time>

            <ol>

                <li>artist 01</li>
                <li>artist 02</li>
                <li>artist 03</li>
                <li>artist 04</li>
                <li>artist 05</li>

            </ol>

        </a>

    </li>

</ul>

As the titel stated I want to look for the time element with a matching date-time attribute value in ul.weeks and then do something. That 'something' I know how to do (I guess :) ), but searching for the matching attribute value, I don't know yet.
Can I even store the date-time attribute value of the time element (in a.index) in a variable, so that I can use that to look for a match in ul.weeks? Or do I have to use data attributes instead.

Edited by gentlemedia

1
Contributor
1
Reply
13
Views
2 Years
Discussion Span
Last Post by gentlemedia
0

Well, let me answer my own question, because I figured it out :)
This will do the trick:

var $dt = $('.index').find('time').attr('datetime');

$('.weeks').find('time').filter(function(){ 
    return $(this).attr('datetime').match($dt) 
});

Edited by gentlemedia

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.