dcsimg
www.webdeveloper.com
Results 1 to 7 of 7

Thread: is this possible with jQuery? replace img based on src value?

  1. #1
    Join Date
    Mar 2010
    Posts
    281

    is this possible with jQuery? replace img based on src value?

    I have a hell CMS to work with and am wondering if i can the following with jQuery (or just straight up JS)

    images are being displayed with no ID's or classes. am wondering if i can replace images based on the src value

    pseudo code would be uh.....something like


    find img where src = /img/00789-reg-1.jpg';
    and replace src value with ='img/much-better-img.jpg';

    thanks -

  2. #2
    Join Date
    May 2004
    Location
    Manhattan NY
    Posts
    6,028
    It can be done with either. When is it supposed to happen? What is the event handler?

  3. #3
    Join Date
    Mar 2010
    Posts
    281
    i guess it would be window.onload

    really it's possible. what would the code be?

    thanks much

    is asap an event handler?

    asap.event();

  4. #4
    Join Date
    Mar 2010
    Posts
    281
    ummm,,.... does anyone know how to do this?, thanks

  5. #5
    Join Date
    May 2004
    Location
    Manhattan NY
    Posts
    6,028
    $(document).ready(function () {
    $("img['src = /img/00789-reg-1.jpg']").attr('src","img['img/much-better-img.jpg']");
    });

  6. #6
    Join Date
    Mar 2010
    Posts
    281
    aye!, thank you.

  7. #7
    Join Date
    Mar 2010
    Posts
    281
    Hey,
    i tried but it didn't work. first there was an error so moved an apostrophe as such..

    $("img[src = '/img/728028233605-FBC-Original-1.jpg']").attr("src","img['img/product1-volusion.jpg']");

    which seemed to correct the error but then nothing happened. as though it's not firing but i have within the document ready
    handler.

    $(document).ready(function(){
    alert('test');
    $("img[src = '/img/728028233605-FBC-Original-1.jpg']").attr("src","img['img/product1-volusion.jpg']");
    })

    any idea why this might not be working.???, was really looking forward to using. also, wanted to try the same with an anchor tag.

    thanks for any help on this

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles