I have this HTML
<div class="picture"></div>
and depending on the viewport width, I'd like to add either a small or a large image to the div, so that it will look like this:
<div class="picture"><img src="small.jpg></div>
Here's some jQuery I found somewhere on the web which seems to do exactly what I want. The only part where I'm stuck now is the img src="....jpg" thing. How can I translate this into jQuery?
jQuery(document).ready(function() {
$(window).resize(function() {
var window_width = $(document).width();
if (window_width <= 1024) {
img src = "small.jpg"
} else {
img src = "large.jpg"
}
});
});
Thanks!