I have a php code that prints some HTML stuff from MYSQL database.
Sometimes there are some img tags in there that don't have any width so I need to find those and add a width attribute via inline CSS to those img tags.
They look like this:
<img class="aligncenter size-medium wp-image-31kj" src="someimage.jpg" alt="">
<img class="alignleft large-medium wp-image-3154" src="someimage.jpg" alt="">
How can I find these img tags and add this to them:
style="width:100%"
Thanks in advance.
EDIT:
Already doing the above using jquery but its not reliable:
$(".img").each(function() {
var imgWidth = $(this).width();
if (imgWidth == 0){
$(this).css('width','100%');
}
});
querySelectorAll('img').forEach()add your checks inside the foreach & apply the styling you want.imgwith a parser, check for awidthattribute, if not present add one.