The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Make Image Source the Background of an Element

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • #38178

    I’m attempting to figure out a JavaScript/jQuery solution that gets the source of image elements and replaces the images with an element that has its background set to the source of said image.

    I’ve written out the following in an attempt to get it working, but it only works on a single image instead of all in the list.

    var slideImgSrc = jQuery('ul.portfolio-slider li.panel img.alignnone').attr('src');
    jQuery('ul.portfolio-slider li.panel img.alignnone').replaceWith('');

    What do I need to do to get it working in the entire list instead of just the first?

    Here’s a jsFiddle:

    Thank you guys. I’m still not comfortable with JavaScript but I’m getting there.


    Here ya go!

    $(document).ready(function() {
    $('img').each(function() {
    var imageURL = $(this).attr('src');

    Sweet, thanks Doc!

Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.