I'm trying to display only the odds from bet365 from a javacript piece of code. I can only think of doing this by searching for a part of the id of the bet, each bookie has its own related ids and bet365's is b3, so this query below I've tried to search for ids where the string includes the "b3" in it, as all other parts of it seem completely random
http://www.oddschecker.com/horse-racing/2015-06-30-chepstow/18:10/winner
var odds = document.getElementsByTagName("odds");
for (var i = 0; i < odds.length; i++) {
if(odds[i].id.indexOf("b3") == 0) {
odds[i].disabled = bDisabled;
}
}
Whenever I do this my return says undefined. How can I get this to work
答案 0 :(得分:0)
It looks like the marker you're looking for is .co
, from what I can see from the code (delimiting a td
with the odds as inner content).
The site also has jQuery loaded up, so let's use jQuery to simplify the pseudo-code (we can always transform it to pure javascript later):
var odds = $('.co');
odds.each(function(){
var id = $(this).attr('id');
if(id.indexOf('_B3') >= 0){
console.log(id);
//your code here
}
});
Given that the ID is not at the end of the ID string, we can't check to see if the indexOf is == to 0; instead, we just want to know if the ID we're looking for (b3) is contained in that string. So we're looking for any value that is not -1, the value returned by indexOf when the query is not found in the original string.
I'm searching for specifically for _B3
for two reasons: One, indexOf is case sensitive, so given that your ID are uppercase, we must make our search uppercase too. I'm also adding the underscore in order to respect the ID string format, as I'm not 100% certain that your ID will only contain letters to delimit IDs from the bet vendor, so we can't be too safe with that.
In pure javascript:
var odds = document.getElementsByClassName('co');
for(var ii = 0; ii < odds.length; ii++){
if(odds[ii].id.indexOf("_B3") >= 0){
console.log(odds[ii].id);
//your code here
}
}