shahid hamdam
shahid hamdam

Reputation: 821

get href of anchor tag in if condition

I have this for loop that outputs dates of one week in tabs.

for ($i = 0; $i <= 7; $i++) {

  $date = date('Y-m-d', strtotime("+$i day", $start));
  $date1 = $date;
  $day1 = date('D', strtotime($date1));
  $date = explode('-', $date);
  $dateinput = date('Y-m-d', strtotime("+$i day", $start));

  $dateinput=explode('-',$dateinput);
  $year=$dateinput[0];
  $month=$dateinput[1];
  $day= $dateinput[2];
  $dateinput=$month.'/'.$day.'/'.$year;
  $dateinput1=$month.'-'.$day.'-'.$year;

  $date = $date[2];


echo '<li class="lia li'.$dateinput.'" id="'.$dateinput1.'" data="'.$dateinput.'">
<input type="hidden"  class="getdate" value="'.$dateinput.'">
 <a href="#tabs-'.$i.'" id="#tabs-'.$i.'" class="date">' . $date . '  ' . $day1 . '</a></li>';

}

I have a Jquery code that match the date selected and the date in tabs. if they match i assign a class to that date's tab.

if( Date.parse(date) == Date.parse(ndate) )
     {

       jQuery("#tabs > .uol > li[data='" + date + "']").addClass("selectedli");

       var href = $(a.dateanchor).attr('href');
       alert(href);

     }

I want the href value of that specific tab where date match. how i can do that? you can see in above code how i tried to get it but it alerts undefined.

Upvotes: 0

Views: 788

Answers (2)

shahid hamdam
shahid hamdam

Reputation: 821

thanks all i have solved my issue on my own.

var tabid = jQuery("#tabs > .uol > li > a[dataa='" + date + "']").attr('href');
      alert(tabid);

Upvotes: 0

Prashant Kapoor
Prashant Kapoor

Reputation: 36

As the selector you are using is not a variable, you have to use it in single or double quotes in your jQuery code.

So the correct syntax here will be any of the below:

var href = $('a.dateanchor').attr('href');

or

var href = $("a.dateanchor").attr('href');

Upvotes: 1

Related Questions