/    Sign up×
Community /Pin to ProfileBookmark

change image links only

I’d like to change this code so that it only affects links which are images. I don’t know a way to specify that though ?

[code] var xpath = “//a[contains(@href, scriptBefore)]”;
var res = document.evaluate(xpath, document, null,
XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
var i, link;
for (i = 0; link = res.snapshotItem(i); i++) {
link.href = link.href.replace(scriptBefore, scriptAfter);
}[/code]

Thanks

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@webstuffJan 02.2006 — You could wrap all images in anchor tags, step through the anchor tags and all those that do not need to click thru can simply be... href="javascript://" which is a null click event, any links with this href, you can ignor.

Tou then can apply the changes to the scripts calls on all other links that do not have the javascript:// setting.

This is the simplest and easiest method of getting to your goal that I can think of, prolly more advanced methods of achieving the same goal but for the time beeing, you have some kind of workable soloution.

Hope this helps you for now.
×

Success!

Help @dave_is_sexy spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.27,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...