how to get img src value

后端 未结 2 1269
迷失自我
迷失自我 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: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");
    

提交回复
热议问题