Reputation: 2724
Whats wrong with this?
var hover = $('<img />').attr('src', hovers[i]).css('position',
'absolute',
'visibility' ,
'hidden');
for some reason the 'visibility' , 'hidden'
does not get called? but if i remove the position style it does.
What am i doing wrong here?
Upvotes: 0
Views: 112
Reputation: 18158
from the css docs you can see that your syntax is not correct, when define mulitple css attributes use :, then comma to separate, also enclose all the attributes in curly brackets, like this:
var hover = $('<img />').attr('src', hovers[i]).css({'position':'absolute','visibility':'hidden'});
Upvotes: 0
Reputation: 414
Change it to this:
var hover = $('<img />').attr('src', hovers[i]).css({'position': 'absolute', 'visibility': 'hidden'});
Upvotes: 0
Reputation: 85135
The answer is to pass an object with key value pairs into the css method rather then passing extra arguments:
var hover = $('<img />')
.attr('src', hovers[i])
.css({
position: 'absolute',
visibility: 'hidden'
});
See the documentation here for ".css(map)": http://api.jquery.com/css/#css2
Upvotes: 4