Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get img src value

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 and to show some div content

for example

if img src value contains "http://google.com/test/test.img" have to highlight and to show img is highlighted div content

if img src value contains some specific path "news/images/test1.jpg" have to highlight and to show img is highlighted div content

if img src value contains some specific path "news/articles/images/test1.gif" no need to highlight and to show img is not highlighted div content.

like image 349
MKN Avatar asked May 04 '10 12:05

MKN


1 Answers

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");
like image 124
karim79 Avatar answered Oct 04 '22 21:10

karim79



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!