Philcyb
Philcyb

Reputation: 165

How to style a DIV if the IMG inside it has broken image?

Still a Newbie using Javascript. I know something's wrong with my function code. I just can't restructure it well.

HTML:

<div class="column">
    <img src="http://placehold.it/200x200&text=IMG1" onerror="imgError(this);" />
</div>
<div class="column">
    <img src="httzp://placehold.it/200x200&text=IMG2" onerror="imgError(this);" />
</div>

JS:

function imgError(image) {
    image.onerror = "";
    parent('div.column').image.css('border','5px solid red');
    return true;
}

JSFiddle Link

Thanks in advance.

Upvotes: 0

Views: 96

Answers (1)

Kartikeya Khosla
Kartikeya Khosla

Reputation: 18893

Try This:

function imgError(image) {
    $(image).parent('div.column').css('border','5px solid red');
}

DEMO

Upvotes: 2

Related Questions