0

Using jQuery how could I obtain the link inside this a tag?

<a title="Rainham Pizza and Kebab" href="/rainham-pizza" class="restsRestStatus restPageLink  restsStatusOpens"><b>Pre-order</b><span>Opens         16:00       </span></a>

I have tried using:

jQuery("a.restsRestStatusrestPageLinkrestsStatusOpens").html();
James Donnelly
  • 126,410
  • 34
  • 208
  • 218
  • 1
    `jQuery("a.restsRestStatus").attr('href')` – Satpal Sep 10 '14 at 10:14
  • 1
    http://stackoverflow.com/questions/4345427/jquery-set-and-get-href http://stackoverflow.com/questions/720970/jquery-hyperlinks-href-value – ale Sep 10 '14 at 10:15
  • possible duplicate of [jquery set and get href](http://stackoverflow.com/questions/4345427/jquery-set-and-get-href) – ale Sep 10 '14 at 10:19

8 Answers8

2
$("a.restsRestStatus.restPageLink.restsStatusOpens").attr("href");
Peter van Kekem
  • 1,387
  • 1
  • 12
  • 30
1

Try using .attr() as shown :-

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

OR

var url = $("a.restsRestStatus.restPageLink.restsStatusOpens").attr("href");
alert(url);
Kartikeya Khosla
  • 18,743
  • 8
  • 43
  • 69
1

You can use .attr() in jquery

("a.restsRestStatus.restPageLink.restsStatusOpens").attr("href")
Anoop Joshi P
  • 25,373
  • 8
  • 32
  • 53
1
var link = $('a.restPageLink').attr('href');
ToX 82
  • 1,064
  • 12
  • 35
0
href = $('a').attr("href");
alert(href);
john Smith
  • 17,409
  • 11
  • 76
  • 117
0

try this...

var link =$(element).attr("href");
Ranga
  • 258
  • 2
  • 13
0

use prop() over attr() in the majority of cases.

prop() is the current state of the input element, attr() is the default value.

prop() can contain things of different types, attr() can only contain strings

var url = $('a.restsRestStatus ').prop('href');
codebased
  • 6,945
  • 9
  • 50
  • 84
0

You need

var href = $(this).attr('href');
Ricard
  • 17
  • 3