it's me again. How I can call data from defined array?
var myArray = new Array("http://www.gravatar.com/avatar.php", "http://1.gravatar.com/avatar/", "http://0.gravatar.com/avatar/");
$('img[src^="DATA FROM myArray"]').remove()
$(myArray).each(function(idx,elem){
/*idx is item index, elem is the item itself*/
$('img[src^="'+elem+'"]').remove();
})
var array = [1, 2, 3] instead of var array = new Array(1, 2, 3)var myArray = [
"http://www.gravatar.com/avatar.php",
"http://1.gravatar.com/avatar/",
"http://0.gravatar.com/avatar/"
];
$('img').filter(function() {
var inArray = false;
var src = $(this).attr('src');
$.each(myArray, function() {
if(src.indexOf(this) == 0)
inArray = true;
}
return inArray;
}).remove()
Or you could just use regex:
$('img').filter(function() {
return $(this).attr('src')
.match(/^http:\/\/(www|0|1)\.gravatar\.com\/avatar(\.php)?/i);
}).remove()
Maybe it's faster to fetch like this:
$("img[src]").filter(function() {
return $.inArray($(this).attr("src"), myArray) != -1;
}).remove();
src starts with an array element, not is an array element.InArray let's you get an the index of an item within an array. So:
myArray[$.inArray("http://www.gravatar.com/avatar.php",myArray)]