Rohit Ramname
Rohit Ramname

Reputation: 834

disable img tag

How to remove href attribute of an img on a page using jquery?

this img tag does not have any class or ID for referencing

Upvotes: 0

Views: 5731

Answers (4)

user605334
user605334

Reputation:

Image tag not have href attribute they have src attribute for image location

using jQuery selector you can remove the src attribute

Please check on its parent object, if it has either id or class attribute you can use any one of the following.

if the parent (for example consider div) has id.

$("div#your-id img").removeAttr('src')

if the parent has class.

$("div.your-class img").removeAttr('src')

Upvotes: 3

Nagarajan Ganesh
Nagarajan Ganesh

Reputation: 573

Image tag not have href attribute they have src attribute for image tag.

Please check on its parent object, if it has either id or class attribute you can use any one of the following.

if the parent (for example consider div) has id.

$("div#your-id img").removeAttr('src')

if the parent has class.

$("div.your-class img").removeAttr('src')

Upvotes: 0

BalusC
BalusC

Reputation: 1108742

The image doesn't have a href attribute. It has a src attribute.

If it's a specific and unique src attribute value, then you can just select by it.

E.g. exact match using the attribute selector

$("img[src='foo.gif']").hide();

or when src starts with a certain domain, using the attribute starts with selector

$("img[src^='http://example.com']").hide();

Upvotes: 0

John K.
John K.

Reputation: 5474

If you know the link then I believe you can do something like

$("a[href='http://www.google.com/']").attr('href', '#')

Upvotes: 0

Related Questions