/    Sign up×
Community /Pin to ProfileBookmark

Hi

I’m having trouble understanding why Firefox would say “links[i].indexOf is not a function on this:

[code=html]
<html>
<head>
<script>
function doStuff(){
var links = document.getElementsByTagName(‘a’);
for(var i=0; i<links.length; i++) {
alert(links[i].indexOf(‘w=0’));
}
}
</script>
</head>

<body>

<a href=”http://blupp”>test</a>
<a href=”http://blupp”>test 2</a>
<a href=”http://blupp&w=0″>test 3</a>

<input type=”button” onclick=”doStuff()” value=”clickme”>

</body>
</html>

[/code]

links[i] is a string, right? I’m trying to see which links contain the w=0 in them you see…

Thanks for your time
Lubox

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@mrhooMar 03.2007 — links[i] is an element, which [B]can [/B]return the string value of its href, just as alert(location) returns the location.href, and not 'object'.



But it isn't a requirement that a user agent behave this way, so get the href specifically:



alert(links[i].href.indexOf('w=0'));
×

Success!

Help @Lubox 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 5.9,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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