Reputation: 1094
I have an image and I am trying to convert its alt text to lower case using jQuery:
I am using the following code:
var altattr = $('img').filter(function(){
return $(this).attr('alt').toLowerCase().indexOf('alt') > -1;
});
Upvotes: 0
Views: 97
Reputation: 4288
You can pass a function as second parameter to the .attr()
method. This function retrieves two arguments, the index and the value. Try with:
$('img').attr('alt', function(){
return arguments[1].toLowerCase();
});
As @AlexeiLevenkov commented, for a better comprehension, see this example:
$('img').attr('alt', function(index, value){
return value.toLowerCase();
});
Check out http://api.jquery.com/attr/#attr-attributeName-function
Upvotes: 3