Antony West
Antony West

Reputation: 19

Get the link form a href using jquery

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();

Upvotes: 0

Views: 141

Answers (8)

Ricard
Ricard

Reputation: 17

You need

var href = $(this).attr('href');

Upvotes: 0

codebased
codebased

Reputation: 7073

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');

Upvotes: 0

Dewz
Dewz

Reputation: 266

try this...

var link =$(element).attr("href");

Upvotes: 0

ToX 82
ToX 82

Reputation: 1074

var link = $('a.restPageLink').attr('href');

Upvotes: 1

john Smith
john Smith

Reputation: 17906

href = $('a').attr("href");
alert(href);

Upvotes: 0

Anoop Joshi P
Anoop Joshi P

Reputation: 25527

You can use .attr() in jquery

("a.restsRestStatus.restPageLink.restsStatusOpens").attr("href")

Upvotes: 1

Peter van Kekem
Peter van Kekem

Reputation: 1447

$("a.restsRestStatus.restPageLink.restsStatusOpens").attr("href");

Upvotes: 2

Kartikeya Khosla
Kartikeya Khosla

Reputation: 18873

Try using .attr() as shown :-

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

OR

var url = $("a.restsRestStatus.restPageLink.restsStatusOpens").attr("href");
alert(url);

Upvotes: 1

Related Questions