how to get img src value

后端 未结 2 1220
迷失自我
迷失自我 2021-01-02 16:41

I have some contents inside div tag...

within that div tag content I have to search for img src tag value

based on that value i have to highlight some images

相关标签:
2条回答
  • 2021-01-02 17:02
    $('#someImage[url="http://google.com/test/test.img"],'
    + '#someImage[url="news/image/test1.jpg"]')
    .addClass("highlight").css("border", "3px solid yellow");
    
    0 讨论(0)
  • 2021-01-02 17:12

    I think you mean that there are two possible scenarios where you want to highlight the image:

    var $img = $("#someImage");
    var src = $img.attr("src");
    if(src == 'http://google.com/test/test.img' || src == 'news/images/test1.jpg') {
        $img.addClass("highlight");
        // or
        $img.css("border", "3px solid yellow");
    }
    

    EDIT based on your comment:

    $("#formpreview img[src*=google.com]").addClass("highlight");
    
    0 讨论(0)
提交回复
热议问题