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

Home Forums JavaScript With JavaScript: Detect an image src and replace it…

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

    Hi there,

    I’m looking for some JavaScript to detect whether a photo on the page exists based on it’s URL and then replace that URL.

    Something like,

    If img.src == THEN img.src=

    Thank you for any help in advance.


    With jQuery it is fairly easy.

    The small script below loops through each image element, checks if the src matches and if so replaces it.

    // Loop trough each image element and replace the src if the src matches
    $("img").each(function(i, elem){
    // If src of img element matches a certain URL then src is new url
    if ($(this).attr("src") == ""){
    $(this).attr("src", "");
Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.