jquery setting an inline width property problem
I am using a jcarousel, and I need to explicitly specify the width of each img. The problem is, that it has to actually see the width="" to work. Is there a way to add an inline width to image. I tried:
<script type="text/javascript">
$(document).ready(function () {
$('.tab-item-photo img').each(function () {
$(this).css("width", "100px");
});
});
It changes the image size but it doesn't add the width to inline style so the function开发者_Go百科ality of jcarousel doesn't work.
Any ideas on this?
Thanks, H.
That's setting the css property, but it sounds like you're talking about the width attribute. Try $(this).attr('width', '100px');
EDIT: There's actually an easier way to implement the same thing that would be a bit less verbose.
Your statement above would be the equivalent of
$('.tab-item-photo img').css('width', '100px');
If changing css
to attr
doesn't work, you could also try adding it to the style attribute. If you know the style attribute is already empty, you could do
$('.tab-item-photo img').attr('style', 'width:100px');
Otherwise, you would have to parse width out of the existing style attribute and add it back in. Ideally, you would just do this with .css()
but that apparently doesn't play well with your jcarousel code.
精彩评论