I’m trying to add an if statement which checks if the image is wider than 199px and if it hasn’t got a < a > parent element.
This works:
$('div.post_body').each(function() {
$(this).find('img').each(function () {
var img = $(this);
if (img.is('a') !== true) {
img.wrap($('<a/>').attr('href', img.attr('src')).addClass('lightview limg'));
}
});
});
This works
$('div.post_body').each(function() {
$(this).find('img').each(function () {
var img = $(this);
if (img.width() > 199) {
img.wrap($('<a/>').attr('href', img.attr('src')).addClass('lightview limg'));
}
});
});
This DOESN’T work:
$('div.post_body').each(function() {
$(this).find('img').each(function () {
var img = $(this);
if ((img.width() > 199) && (img.is('a') !== true)) {
img.wrap($('<a/>').attr('href', img.attr('src')).addClass('lightview limg'));
}
});
});
Can someone help please?
So you want all images directly inside the
divthat exceed a certain dimension?Demo: http://jsfiddle.net/BQAZH/1/